I'm struggling to comprehend the details of the MIPS jump instruction encoding, specifically when dealing with the instruction located at address 0x00400008. The context involves the jump to the address specified by foo, where the label foo is at address 0x00400024.
The answer should be 0x08100009.
From what I know, you need to compute the jump target address using the given information:
- Two least significant bits are always 0 due to word alignment.
- Four most significant bits are from the PC+4, and that we set addr = target >> 2.
- Expected result: 0x08100009.
But if the 2 least significant bits are 0, why do we end up with the number 0x0…9?


Judging from the expected result, you are actually encoding the instruction not trying to decode the jump target that the formula applies to. Also it uses
address(label)incorrectly: it's missing a bit range 27:2. Chopping off the 2 least significant bits is equivalent to dividing by 4. The rationale is that instructions are 32 bits in size and naturally aligned so you don't need to store the two zero bits at the end.To get the machine code you need to know the instruction format which is simply
0000 10 address[27:2]in binary. The0000 10is the opcode.In your case the target address is
0x00400024. Just divide by 4 to get the appropriate bits:0x100009. Prepend the opcode to get the expected0x08100009(beware that the opcode is 6 bits so you have to be careful doing it in hex)