我复制了一张MIPS - Aseembly上的作业图片.
我理解(我认为)在代码中会发生什么:
beq $11, $0, 3
Run Code Online (Sandbox Code Playgroud)
我知道代码现在为地址创建了一个PC-RELATIVE分支:
PC+4+3*4
Run Code Online (Sandbox Code Playgroud)
但是我不明白这个代码到底是怎么发生的 - 下一行是什么?
我会更清楚地提出我的问题:
Row 1: adds 15 to zero, puts it in $a0 register.
Row 2: ANDs $a0 register with 3, puts the result in $a0.
Row 3: ORs $a0 register with 22, puts the result in $a0.
Row 4: shifts $a0 to the left by 5 bits. Result - in $a0.
Row 5: if $a0 equals $a0, go to PC+4+6*24 address. The address is Row 7 which is:
slt $11, $10, $9
Run Code Online (Sandbox Code Playgroud)
这将值0放在$ t3寄存器中,因为10美元= 9美元.
现在我进入第8行:
beq $11, $0, 3.
Run Code Online (Sandbox Code Playgroud)
第8行做什么?
任何帮助都是适当的.

小智 2
beq $11, $0, 3beq表示跳转到if前面的第三条指令$11 == $0。例如:
beq $11, $0, 3
instruction 1
instruction 2
instruction 3 < the target
Run Code Online (Sandbox Code Playgroud)
该数字3将首先进行符号扩展,然后添加到程序计数器中,$pc如下所示:
$pc = $pc + 3 * 4
Run Code Online (Sandbox Code Playgroud)
或者简单地:
$pc = $pc + 3 << 2
Run Code Online (Sandbox Code Playgroud)
这4是因为每条 MIPS 指令都是 4 字节大小。