Shifting the Sign extended constant in MIPS

Alfred picture Alfred · Dec 7, 2012 · Viewed 11.8k times · Source

Why do we shift by 2 the sign extended 16bit constant in branching instruction in MIPS? I am confused with this idea. What good does this shifting brings to the sign extended 16 bit constant. Here is the picture:

enter image description here

Regards

Answer

Paul R picture Paul R · Dec 7, 2012

MIPS instructions are 32 bits = 4 bytes, so the branch offset is specified as a multiple of 4, i.e. a branch offset of 1 = 4 bytes. This enables a much larger range of branch offsets than if the offset were specified in bytes (as there would then be two redundant bits). Shifting left by 2 is the same as multiplying by 4, of course.