1
votes

I am learning MIPS right now, and as I was reading the documentation, it said:

An 18-bit signed offset (the 16-bit offset field shifted left 2 bits)

I was wondering why exactly for branch instructions the offset is being multiplied by 4? The documentation also stated that this makes the range for branch instructions 128 kb because the 32kb is multiplied by 4. Does this multiplication only apply to branch instructions or does it also apply to Jump instructions as well?

Thanks!

1

1 Answers

2
votes

I was wondering why exactly for branch instructions the offset is being multiplied by 4?

All instructions must be word-aligned. From that it follows that both the origin and the destination are word-aligned, which in turn means that the offset also always will be word-aligned. So it would be a waste to store the two least significant bits of the offset since they always will be 0. Instead we can use the available bits in the instruction word to encode 18-bit offsets by storing only the 16 most significant bits.

Does this multiplication only apply to branch instructions or does it also apply to Jump instructions as well?

It's the same for jump instructions. Though jump instructions differ in other ways; the offset for a jump is not PC-relative, but relative to the start of the 256MB-aligned region that the PC currently is in.