I'm not sure if this is useful to you now, but I post it anyway.
Consider, in a very general sense, an array of instructions in C ++, that is, A [0], A [1], A [2] ..... The "figurative" distance between any two instructions is 1 UNIT.
Let's look at this analogy with MIPS. In MIPS, figuratively each instruction is separated by "1 UNIT", however 1 UNIT = 4 bytes in MIPS. Each instruction has a length of 4 bytes, and therefore, when switching from a command to a PC command, it increases by 4, that is, on PC + 4. Thus, the gap between instruction I and instruction I + 2 is “figurative” 2, but actually 2 * 4 = 8, i.e. PC + 4 + 4
Returning to the offsets specified in the Branch instructions, the offset is the “shaped" distance from the next command (the instruction following the branch). Thus, in order to get the “real” distance, the offset must be multiplied by 4. This is the reason that we are instructed to “sign-extend” the 2-bit offset by “LEFT”, since the left shift of any binary value by n bits results in by multiplying this value by 2 ^ n. In our case, 2 ^ 2 = 4
Thus, the actual destination address of the jump instruction is PC + 4 + 4 * Offset.
Hope this helps.
Jonna
source share