MIPS 跳转指令共分为三类:基于PC的相对跳转、基于PC区域的相对跳转、基于寄存器的绝对跳转。其中基于 PC 区域的相对跳转也就是我们要说的 J 类指令。
J类指令有长达26位的指令 index 编码域,因为指令都是4字节对齐的,所有表示的范围是 256M(28位)。那么J类跳转的目标地址是如何计算的呢?
目标PC = 延迟槽指令PC的28位以上的高位 || (J类指令26位的立即数 << 2)
是不是不易想像范围,看看图示吧:
j-class
|: 265M 边界
j: j 指令位置
t: 可行的跳转目标位置
----------------|--------------------------------|--------------------------------|----------------
---------------j|tttttttttttttttttttttttttttttttt|--------------------------------|----------------
----------------j-ttttttttttttttttttttttttttttttt|--------------------------------|----------------
----------------|j-tttttttttttttttttttttttttttttt|--------------------------------|----------------
----------------|tttttttttttttttj-ttttttttttttttt|--------------------------------|----------------
----------------|ttttttttttttttttttttttttttttttj-|--------------------------------|----------------
----------------|-------------------------------j|tttttttttttttttttttttttttttttttt|----------------
----------------|--------------------------------j-ttttttttttttttttttttttttttttttt|----------------
Over!