为什么我的 jal 从 pc 上获得的 +4 比它应该得到的多?

why is my jal getting +4 more than it should from pc?

所以我的 jal 运营商看起来不像是在做它应该做的事情。看起来它比它应该抓取的地址节省了 4 个地址。我的测试代码是:

.data

test: .asciiz "test"
test1: .asciiz "test1"
test2: .asciiz "test2"
.text
main:
la $a0, test
li $v0, 4
syscall
li $t9, 5 # messing with line before jal
jal next
li $v0, 10 
syscall
# it should never hit this code
la $a0, test1
li $v0, 4
syscall
next:
la $a0, test2
li $v0, 4
syscall
jr $ra
li $a0, 1 # it should never hit this code
li $v0, 1
syscall

输出是:"Go: execution terminated with errors."代码并不重要,它只是假设显示 jal 的问题,有谁知道如何修复 pc 或 jal? (我已经重新安装了 mars 和 java。)
printscreenofjal

我觉得你在 Mars 的设置中启用了延迟分支。

如果您查看 MIPS32™ Architecture For Programmers 中对 JAL 的描述 第二卷:MIPS32™ 指令集 您会发现您所描述的实际上是正确的和预期的行为:

Place the return address link in GPR 31. The return link is the address of the second instruction following the branch, at which location execution continues after a procedure call.

这是因为 MIPS 处理器使用延迟分支,这会导致紧跟在分支指令之后的指令在分支目标处继续执行之前执行。作为程序员,这意味着您必须注意填充分支延迟槽,方法是在所有分支指令之后插入 NOP,或者重新组织代码。

请注意,默认情况下延迟分支是禁用的,如果我 运行 你在火星上的程序禁用了延迟分支,我会得到以下输出:

testtest2
-- program is finished running --