riscv_asm/libzomutils.s

58 lines
1 KiB
ArmAsm
Raw Normal View History

2024-11-23 00:46:33 -05:00
.text
2024-11-24 23:51:08 -05:00
.globl len
.globl puts
.globl exit
2024-11-23 00:46:33 -05:00
len:
mv t0, a0
mv t1, t0
lenloop:
lb t2, (t1)
beq t2, x0, lencleanup
addi t1, t1, 1
j lenloop
lencleanup:
sub a0, t1, t0
ret
puts:
#here a0 should be the pointer to the string
#save s2 becuase we are gonna use it
addi sp, sp, -16
sd s2, 12(sp)
#save a0 because we need it later
mv s2, a0
#get length because the stdout systemcall needs it in a2
addi sp, sp, -16 # Allocate stack space
sd ra, 12(sp) # Save return address
jal ra, len
ld ra, 12(sp) # Restore return address
addi sp, sp, 16 # Deallocate stack space
#a0 should be the length
mv a2, a0 #stdout expects it in a2
li a0, 1 # file descriptor = 1 (stdout)
li a7, 64 # syscall write (64)
mv a1, s2 #this should still be the pointer to the text
#restore s2 for the next guy
ld s2, 12(sp)
addi sp, sp, 16
ecall
ret
exit:
li a0, 0 # exit code
li a7, 93 # syscall exit
ecall