commit 3187a3bd0b854dafc2e58107bcccb9143c16296a Author: lexzach Date: Fri Sep 11 19:03:06 2026 -0400 Add argc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..87fe527 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +bin +build \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bdc2a33 --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +AS := riscv64-linux-gnu-as +LD := riscv64-linux-gnu-ld + +SRC_DIR := src +BUILD_DIR := build +BIN_DIR := bin + +SRCS := $(wildcard $(SRC_DIR)/*.S) +OBJS := $(SRCS:$(SRC_DIR)/%.S=$(BUILD_DIR)/%.o) + +TARGET := $(BIN_DIR)/cat + +.PHONY: all clean + +all: $(TARGET) + +$(TARGET): $(OBJS) | $(BIN_DIR) + $(LD) $(OBJS) -o $@ + +$(BUILD_DIR)/%.o: $(SRC_DIR)/%.S | $(BUILD_DIR) + $(AS) $< -o $@ + +$(BUILD_DIR) $(BIN_DIR): + mkdir -p $@ + +clean: + rm -rf $(BUILD_DIR) $(BIN_DIR) \ No newline at end of file diff --git a/src/args.S b/src/args.S new file mode 100644 index 0000000..09bfb12 --- /dev/null +++ b/src/args.S @@ -0,0 +1,9 @@ +.globl fetch_argc, fetch_argv + +# Fetch argument count +# @param[in] a0: unused. +# @param[out] a0: number of arguments. +fetch_argc: + ld a0, 0(sp) + ret + \ No newline at end of file diff --git a/src/main.S b/src/main.S new file mode 100644 index 0000000..1dba456 --- /dev/null +++ b/src/main.S @@ -0,0 +1,28 @@ +.data +argc: .space 8 + +.section .text +.globl _start + +_start: + .option push + .option norelax + la gp, __global_pointer$ + .option pop + + + call fetch_argc + li t0, 48 + add a0, a0, t0 + sd a0, argc, t0 + + + li a0, 1 + la a1, argc + li a2, 1 + li a7, 64 + ecall + + li a0, 0 + li a7, 93 + ecall # return 0