riscv_asm/funnyhello.s
2024-11-23 00:46:33 -05:00

78 lines
1.5 KiB
ArmAsm

.text
.globl _start
_start:
ld a0, 8(sp)
jal ra, puts
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:
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
.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