0
votes

I am new to Mips and I need your help. I came across an exercise :

Assuming that the program counter has the 2000 0000hex value in it, is it possible that the program counter will get the 00001000hex or the 20001400hex value using the beq or the jump instruction

First of all I can't really understand what is being represented by the 16bits value of the beq instruction and the 26bits value of the jump instruction. Is it an offset or is it an address?To be honest i think it is an address but I can't really understand how it works.

The answer to the exercise is that for the 00001000hex value both instructions can take you there but for the second one only the jump instruction will work. Why is that? Any help would be appreciated.

1

1 Answers

3
votes

branch on MIPS holds a 16-bit displacement (relative to the next instruction), measured as a signed number of instructions. So you can get from address 0x2000 0000 to 0x2000 1400 by a branch with offset +(0x1400/4-1) = 4FF. You can't get to 0x0000 1000, because that takes an offset of -(1FFF000/4+1) = -7FFC01, more than 16 bits.

jump contains a 26 bit value, representing an absolute address calculated like this:
(encoded value * 4) | (next instruction & 0xE0000000) i.e., the uppermost 4 bit are taken from the instruction after the jump. So you can get from 0x2000 0000 to 0x2000 1400 by jump instr-index=0x500, but you can't get to 0x0000 1000, because whatever you do, the 4 highest bits in your new address will be 0x2, not 0x0.

If you want an instruction that can take you anywhere you want, MIPS has the jr instruction, jump register. Since a register contains a 32-bit value, it can take you anywhere within a 32-bit address space.