0
$\begingroup$

In pseudo direct addressing mode (For the MIPS architecture) the 26 bit of the jump instruction are joined to the upper 4 bits of the PC .

  • how could this help in jumping to relative positions suppose I want to jump backward instead of forward ( i.e. if i want to jump to the beginning of a loop after executing it's body ),

  • What I get is this will limit the jump to be 2^28 from the following instruction but Is this applicable backward too ? I am really confused by this so excuse me for such a silly question...

$\endgroup$
2
  • $\begingroup$ I think how addressing works will depend on the specific architecture. Which CPU architecture are you studying? Please edit your question to provide a little bit of context. $\endgroup$ – D.W. Mar 26 '20 at 19:31
  • $\begingroup$ @D.W. sorry I just thought it's the same , I am reading the 'computer organization and design ...' in which it uses the mips architecture. $\endgroup$ – Mahmoud Salah Mar 27 '20 at 17:11
2
$\begingroup$

Pseudo direct addressing is not intended for relative jumps. It is an absolute jump. If you want a relative jump, don't use pseudo direct addressing.

It's not correct that the limit is $2^{28}$ past the current address. Suppose the current address is 0x183020C0 (to give an example). Then pseudo direct addressing will allow jumping to any address in the range 0x10000000 - 0x1FFFFFFC. Notice that this is up to 0x083020C0 backwards and up to 0xF7CFDF3C forwards from where you currently are; but crucially, those values depend on the current PC. This is not a PC-relative jump. It is a jump to a fixed, absolute constant address.

Typically the code segment will fit within 256MB, so this is typically sufficient to jump to any (fixed) instruction within the code segment.

$\endgroup$
2
  • $\begingroup$ what if the current PC value is already 0x10000000 this way you can't jump any backward this is relative to what PC is pointing at . right ? $\endgroup$ – Mahmoud Salah Mar 27 '20 at 17:54
  • 1
    $\begingroup$ @MahmoudSalah, yes, then you can only jump to instructions that are later, not earlier. $\endgroup$ – D.W. Mar 27 '20 at 18:07
2
$\begingroup$

In MIPS-speak, these areas of memory of 28 (26+2; the +2 is because instructions are four bytes in size) bit address space (256MB) are referred to as "superblocks". Pseudo-direct addressing allows you to jump anywhere within the same superblock. It doesn't matter if it's forwards or backwards.

This was never a problem in practice because it's very rare for a single binary (whether it's an executable or a shared library) to have more than 256MB of code. IIRC, the MIPS linker could handle it if it ever occurred by generating a trampoline. Suppose that the compiler generated a jal, for example, where the linker discovered that the target was in a different superblock. Then the linker would generate a couple of instructions to do the full jump, and point the jal to that.

$\endgroup$
2
  • $\begingroup$ still didn't get how it can jump backward if it just concatenating the 26 bit to the first 4 bits of the PC i.e. could you please give an example of a value in PC which will be modified to jump backward ? $\endgroup$ – Mahmoud Salah Mar 27 '20 at 17:17
  • $\begingroup$ Imagine the instruction that you're jumping from is the last one in the superblock. $\endgroup$ – Pseudonym Mar 27 '20 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.