8

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?

stevenvh
  • 145,145
  • 21
  • 455
  • 667
Jiew Meng
  • 569
  • 2
  • 12
  • 21
  • 2
    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. – tcrosley Oct 14 '11 at 16:44
  • 1
    @tcrosley and the close voter - Please submit your opinion at [this Meta discussion](http://meta.electronics.stackexchange.com/questions/852/where-do-we-draw-the-line-for-code-being-on-or-off-topic) – Kevin Vermeer Oct 14 '11 at 18:41

1 Answers1

6

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.

tcrosley
  • 47,708
  • 5
  • 97
  • 161
  • So i suppose the 256MB comes from 2^28? – Jiew Meng Oct 15 '11 at 00:55
  • @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. – tcrosley Oct 15 '11 at 05:25