[英]MIPS32 assembly beq instruction explanation
Can someone explain why this following assembly line makes sense ? 有人可以解释为什么下面的装配线有意义吗?
beq $0, $0, 1
Note that $0 refers to a register that always have the value of 0. So we are saying if $0 = $0 then go to PC + 4 + 1 else go to next instruction. 请注意,$ 0指的是一个始终值为0的寄存器。因此,如果$ 0 = $ 0,则转到PC + 4 + 1,否则转到下一条指令。
My confusion comes from the immediate field of beq instruction which is 1. Does this mean we are going to address PC + 5 ??? 我的困惑来自beq指令的立即数,即1。这是否意味着我们要处理PC + 5? Doesn't MIPS requires alignment when accessing memory and all memory locations have to be divisible by 4 ?
MIPS在访问内存时是否需要对齐,并且所有内存位置都必须被4整除?
Note that the book says that this instruction just skips the next instruction. 请注意,这本书说该指令只是跳过下一条指令。
The semantic of beq $t, $s, offset
is beq $t, $s, offset
的语义为
if ($t == $s)
PC = PC + 4 + 4 * offset;
else
PC = PC + 4
Simply put the PC is always advanced by 4 by the time the instruction is executed and the immediate is assumed missing the lower two bits since they are always zero and can be reintroduced with a shift ( offset * 4
= offset << 2
). 简而言之,在指令执行时PC总是前进4,并且假定立即数缺少低两位,因为它们始终为零,并且可以通过移位重新引入(
offset * 4
= offset << 2
)。
beq $0, $0, 1
just skip the next instruction as it tautologically set PC = PC + 8
. beq $0, $0, 1
只是跳过了下一条指令,因为它是重言式设置PC = PC + 8
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.