[英]16 bits hex range for mips assembly instruction beq and bne
I have implemented beq instruction for mips assembly language. 我已经为mips汇编语言实现了beq指令。 As my understanding for beq instruction (
beq $s, $t, i
), i can take on integer values or hex values. 根据我对beq指令(
beq $s, $t, i
)的理解,我可以采用整数值或十六进制值。 I have establish a bound for 16 bits integer value. 我已经为16位整数值建立了界限。 I was wondering what is the bound for 16 bits hex values, so when i is too large (or too small?) it would output error before executing it.
我想知道16位十六进制值的界限是什么,所以当我太大(或太小?)时,它将在执行之前输出错误。 Following is beq instruction in binary.
以下是二进制的beq指令。
Branch On Equal
beq $s, $t, i
0001 00ss ssst tttt iiii iiii iiii iiii
I tried (i > 0xffff) but it seems not cover all the cases. 我尝试了(i> 0xffff),但似乎无法涵盖所有情况。 What should i do here?
我在这里该怎么办? Thanks.
谢谢。
It should be in between 0
and 2^16 - 1
for hex(0 <= i <= 65535);
hex(0 <= i <= 65535);
应在0
到2^16 - 1
hex(0 <= i <= 65535);
It should be in between -2^15
and 2^15 - 1
for int(-32768<=i<=32767)
对于
int(-32768<=i<=32767)
它应该在-2^15
和2^15 - 1
int(-32768<=i<=32767)
When you need to conditionally branch farther than +- 2^15 instructions (byte offset = two's complement 16 bits << 2), you can conditionally jump over a non-conditional jump that can reach the target. 当您需要有条件地分支超过+-2 ^ 15条指令(字节偏移=二进制补码16位<< 2)时,可以有条件地跳过可以到达目标的无条件跳转。
beq $s, $t, target # short jump, approx +- 2^17 bytes
vs. j
uses pseudo-direct addressing , keeping the top 4 bits of PC and replacing the rest with a 26-bit << 2 immediate. 与
j
使用伪直接寻址 ,保持PC的前4位,用26位的<< 2立即更换休息。 This lets you reach any target address in the same aligned 1/16th of address space as your code. 这使您可以在与代码相同的对齐地址空间的1/16中到达任何目标地址。
bne $s, $t, .nojump
j target # anywhere with the same top 4 bits
.nojump:
vs. putting the address in a register and using jr
to reach any 32-bit address: 与将地址放入寄存器并使用
jr
到达任何32位地址相比:
bne $s, $t, .nojump
lui $t0, %hi(target)
ori $t0, $t0, %lo(target) # this is what la $t0, target does. It might use addui, but whatever
jr $t0
.nojump:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.