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

59 lines
870 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
# Jump to 'just_after'
auipc ra, 0
jalr 16(ra)
# Jump far to test jalr with negative offset
jal fnfar
ebreak
# just_after : address is 16 bytes after auipc
just_after:
# ra must still be the old address
ret
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
fnneg:
addi a0, zero, 0
ebreak
fnfar:
auipc ra, 0
jalr -8(ra)
ebreak