I have a short snippet of RISC-V assembly that I'm having trouble understanding. I'm not sure if I'm interpreting the instructions wrong, from my interpretation it seems as if the branch (BNE) will be taken but it is given that it should not be.
Given commented code:
000001b8 <test_4>:
lui sp,0xfffff # -> load [sp] = 0xfffff000
addi sp,sp,-96 # -> add -96 to [sp], resulting in [sp] = 0xffffefa0
sb sp,2(ra) # -> store 0xffffffff (sign extend [23:16] of [sp]) to memory
lh a4,2(ra) # -> load halfword from data memory to [a4] = 0xffffffff
lui t2,0xfffff
addi t2,t2,-96 # -> [t2] = 0xffffefa0
li gp,4
bne a4,t2,56c <fail> # -> guaranteed fail since 0xffffffff != 0xffffefa0?
Any help would be greatly appreciated!