Search code examples
mips32

JUMP instruction in MIPS


We express the target address in JUMP instruction only by 26 bits so this address becomes dependent on current PC+4 value. Consider the case when the instruction that I want to jump to is located in my code at

0010&[my_target = 26 bits]&00

but instead we'll jump to the wrong address that starts with 0011 ( to 0011&[my_target = 26 bits]$00 ) because the PC was already incremented to such value that changed its 4th bit.

Is this case really possible?

If it is, how it can be solved?

Thanx


Solution

  • Is this case really possible?

    Yes, it is. Quoting from MIPS32™ Architecture For Programmers Volume II: The MIPS32™ Instruction Set:

    When the jump instruction is in the last word of a 256 MB region, it can branch only to the following 256 MB region containing the branch delay slot.


    If it is, how it can be solved?

    Load the address you want to jump to into a register and then use the jr instruction.