Complete single file cat

This commit is contained in:
2026-09-11 22:27:24 -04:00
parent 31849a5c74
commit fe856ff3d9
3 changed files with 53 additions and 12 deletions
+38
View File
@@ -0,0 +1,38 @@
.data
cat_buf: .space 4096
.section .text
.globl cat_file
# Fetch argument count
# @param[in] a0: ptr to null-terminated file str.
# @param[out] a0: result code.
cat_file:
mv a1, a0 # since the function takes in a0, move it to a1 for syscall
li a0, -100 # relative/absolute path
li a2, 0 # readonly
li a7, 56 # open
ecall
mv t0, a0 # put fd in t0
1:
mv a0, t0
la a1, cat_buf
li a2, 4096
li a7, 63
ecall
blez a0, 2f
mv a2, a0 # move bytes read into bytes needed to write
li a0, 1
la a1, cat_buf
li a7, 64
ecall
j 1b
2:
ret