What is the correct behavior of "jalr $ a0, $ a0"?

I came across an instruction jalr $t1, $t2that supposedly sets $ t1 to the return address and goes into $ t2. However, there seems to be some ambiguity as to which operation takes place in the first place. For example, MARS and SPIM work differently:

.text
main:
    la $t0, func
    jalr $t0, $t0
    # ...
    li $v0, 10
    syscall        # Exit program

func:
    # ...
    jr $t0

In MARS, it is $t0first set to pc + 4(return address) and then goes to $t0, so the code under funcnever starts. However, SPIM seems to do oppsite: jump first, then set the value $t0(previous) pc + 4; therefore funccalled and executed as usual.

So my question is, which simulator implements the correct behavior in this case?

+4
2

Imagination Technologies The MIPS32® Instruction Set v5.03 (, )

Format: JALR rs (rd = 31 implied)  
        JALR rd, rs

:

rs rd , . . , , . ))

, .

+3

MIPS :

Operation:
    I:  temp ← GPR[rs]
        GPR[rd] ← PC + 8
    I+1:if Config1CA = 0 then
            PC ← temp
        else
            PC ← temp<sub>GPRLEN-1..1</sub> || 0
            ISAMode ← temp<sub>0</sub>
        endif

, , SPIM , MARS .

+1

Source: https://habr.com/ru/post/1537546/


All Articles