Could anyone explain how does Pseudo Direct Addressing work in MIPS?

I don't really get how does using the last 4 bits from the PC (Program Counter) fit into the picture?

Suppose I want to goto Address

0000 0000 0000 0000 0000 0000 0000 0100

And my PC looks like 0101 ...

Then I can't? Because I will need the last 4 bits to look like 0101 instead? So it will somewhat be relative to PC too?

  • 2
    \$\begingroup\$ Why the vote to close? In general, microcontroller programming questions have been allowed in this forum. Note under RELATED in the right sidebar the number of MIPS questions. \$\endgroup\$
    – tcrosley
    Oct 14 '11 at 16:44
  • 1
    \$\begingroup\$ @tcrosley and the close voter - Please submit your opinion at this Meta discussion \$\endgroup\$ Oct 14 '11 at 18:41

MIPS pseudo-direct addressing takes the upper four bits of the program counter, concatenated with the 26 bits of the direct address from the instruction, concatenated with two bits of 0 0:

PC31...PC28    IM25...IM00    0    0

which creates a complete 32-bit address. This format is used by the J-type instructions, j and jal. Since the upper 4 bits of the PC are used, this constrains the jump target to anywhere within the current 256 MB block of code (1/16 of the total 4 GB address space). To jump anywhere within the 4 GB space, the R-type instructions jr and jalr are used, where the complete 32-bit target address is specified in a register.

The reason for forcing the bottom two bits to 0 is that all instruction addresses in MIPS are 32-bit word aligned, so you can never have a target address of a jump instruction with the two bits anything other than 0 0.

  • \$\begingroup\$ So i suppose the 256MB comes from 2^28? \$\endgroup\$
    – Jiew Meng
    Oct 15 '11 at 0:55
  • \$\begingroup\$ @jiewmeng, correct. The top 4 bits, coming from the program counter, select 1 of 16 "banks" of 256 MB, and the low 28 bits select a byte within that bank. But as previously mentioned, only bytes with an address modulo 4 == 0 are allowed since the bottom two bits are always 0 0. \$\endgroup\$
    – tcrosley
    Oct 15 '11 at 5: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.