a risc-v simulator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
vriscv/tests/jalr.s

48 lines
730 B

.global _start
_start:
# Set base value of a0 to 'test failed'
addi a0, zero, 1
# Setup a stack
addi sp, sp, 0x100
# Try to call a simple function
jal fn1
# Try to call two imbricated functions
jal fn0
auipc ra, 0
jalr 12(ra)
ebreak
# just_after : address is 12 bytes after auipc
just_after:
# ra must still be the old address
addi a0, zero, 0
ret
addi a0, zero, 1
ebreak
# fn0 : function that calls fn1 and returns
fn0:
# Make space on the stack
addi sp, sp, -4
# Save ra
sw ra, 0(sp)
# Call fn1
jal fn1
# Restore ra and stack
lw ra, 0(sp)
addi sp, sp, 4
ret
ebreak
# fn1 : just return
fn1:
ret
ebreak