I'm currently doing a small project on risc-v. The problem is that, in a function, when I do something like this,
foo:
...
lw a3, 4(sp)
srli a2, a2, 16
srli a4, a4, 16
add a0, a2, a4
ret
after executing add a0, a2, a4 the value of a2 and a4 also change. for e.g. if I comment out the add a0, a2, a4 and execute it, the result: a0 = 0x33333333, a2 = a4 = 0x00000000. If I add the "add" line, the result becomes : a0 = ax000063e3, a3=0x123392c8, a4=0x00000d6e, a2 = 0x00005675.
Even it is the last statement of the function, it also changes the value of the registers that are above it. (like a3)
Am I missing something about risc-v? is it not sequentially executed?
Also in the function to make the result become 0,
...
beq a1, zero, exit_loop
...
exit_loop:
add a0, zero, zero
j finish
...
finish:
addi sp, sp, 28
ret
But this returns 0x00000001.If I'm understanding the fundamental parts of risc-v, let me know. Thanks.
User contributions licensed under CC BY-SA 3.0