Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shifting the Sign extended constant in MIPS

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

like image 938
Alfred Avatar asked Dec 05 '22 13:12

Alfred


1 Answers

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.

like image 70
Paul R Avatar answered Jan 17 '23 21:01

Paul R