What is the range of addresses for a conditional branch instruction in MIPS with respect to X, where X contains the address of the branch instruction? Assume the current PC value is 0x10000000.
What is the range of addresses for jump (j) and the jump and link (jal) in- structions in MIPS. Assume the current PC value is 0x10000000.
(I am totally new to MIPS and I'm not sure how to calculate these values. All I know is that PC_dest = PC_br+4+(offset<<2) ). Thanks in advance!
Best How To :
Conditional branches are I type instructions, they have 16 bit immediate field. If the condition is met,
PC is updated as
PC += immediate << 2.
PC is the address of the conditional jump. The immediate is a two complement value (to jump back eventually), so the range is from
For J instructions (like J) the immediate is 26 bit in two complement. However as markgz remembered me in comments the PC is update as:
PC = PC & 0xf0000000 + immediate << 2, the the immediate set the low bits (from 27 to 2 included) of the new
PC but bits 0 and 1 (as MIPS instructions are 32 bit wide).