1

I'm working with MIPS in Mars. If I'm given the address of an instruction, how do I find the decimal value in the immediate field for the instruction.

i.e. beq $t0, $t1, someLabel - at address (in decimal) 08

John
  • 77
  • 2
  • 11

1 Answers1

0

This form of branch addressing is called PC-relative addressing. Since all MIPS instructions are 4 bytes long, MIPS stretches the distance of the branch by having PC-relative addressing refer to the number of words to the next instruction instead of the number of bytes. Thus, the 16-bit field can branch four times as far by interpreting the field as a relative word address rather than as a relative byte address. Refer to pic attached. (cred:Computer Organisation and Design David & John)

As we can see the address is 80000 (in decimal). So, in PC relative we get the difference of target and next address /4.

For your question We use

Target (decimal) = (immediate*4)+next instruction (address in decimal)

And your answer is

(Target - next instruction)/4 (this is the third value (immediate field) in the beq statement)