made it more of a library

This commit is contained in:
zombie maniac 2024-11-24 23:51:08 -05:00
parent 51bef30657
commit 9312bf9a64
Signed by: nbrooks211
GPG key ID: F43C85C0DF0C334E
4 changed files with 58 additions and 37 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
build/

42
Makefile Normal file
View file

@ -0,0 +1,42 @@
# Compiler and flags
CC = clang
CFLAGS = --target=riscv32 -march=rv64gc_zbb -mabi=lp64 -mno-relax -g
# Directories and files
BUILD_DIR = build
ZOMUTILS_SRC = libzomutils.s
ZOMUTILS_OBJ = $(BUILD_DIR)/libzomutils.o
ZOMUTILS_LIB = $(BUILD_DIR)/libzomutils.a
HELLO_SRC = hello.s
HELLO_OBJ = $(BUILD_DIR)/hello.o
HELLO_BIN = $(BUILD_DIR)/hello
# Default target
all: $(HELLO_BIN)
# Ensure build directory exists
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
# Build libzomutils object file
$(ZOMUTILS_OBJ): $(ZOMUTILS_SRC) | $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
# Create static library libzomutils.a
$(ZOMUTILS_LIB): $(ZOMUTILS_OBJ)
ar rcs $@ $^
# Build hello object file
$(HELLO_OBJ): $(HELLO_SRC) | $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
# Link hello executable with libzomutils.a
$(HELLO_BIN): $(HELLO_OBJ) $(ZOMUTILS_LIB)
$(CC) $(CFLAGS) -nostdlib $^ -o $@
# Clean up generated files
clean:
rm -rf $(BUILD_DIR)
.PHONY: all clean

25
hello.s
View file

@ -1,17 +1,16 @@
.globl _start .section .data
message:
.asciz "Hello from libzomutils!\n"
.section .text
.global _start
_start: _start:
li a0, 1 # file descriptor = 1 (stdout) # Load the address of the message into a0 (first argument register)
la a1, string # buffer la a0, message
li a2, 19 # size
li a7, 64 # syscall write (64)
ecall
_end: # Call the puts function from libzomutils
call puts
li a0, 0 # exit code # Exit the program
li a7, 93 # syscall exit call exit
ecall
string: .asciz "Hello! It works!!!\n"

View file

@ -1,23 +1,8 @@
.text .text
.globl _start
_start: .globl len
ld a0, 8(sp) .globl puts
jal ra, puts .globl exit
la a0, helloworld
jal ra, puts
la a0, incomingflag
jal ra, puts
ld t2, flagmyballs
ror t2, t2, 01
la t1, flagmyballs
sd t2, 0(t1)
la a0, flagmyballs
jal ra, puts
j exit
len: len:
mv t0, a0 mv t0, a0
@ -70,9 +55,3 @@ exit:
li a7, 93 # syscall exit li a7, 93 # syscall exit
ecall ecall
.data
helloworld: .asciz "Hello! It works!!!\n"
incomingflag: .asciz "The flag you gotta fix should be right after the newline\n"
flagmyballs:
# .dword 0x7370617263363400
.dword 0x0343663726170730