The MIPS branch instructions modify the program counter PC b
The MIPS branch instructions modify the program counter (PC) by adding an immediate two\'s complement value.
a) What does this value represent?
b) Why is this value multiplied by 4 before being added to the program counter?
Solution
Let us explain this by taking an example : -
Lets say Program Counter is at $20D and wants to go to location $202 .
The differennce is $20D - $202 = $0B . So the displacement is -$0B. [It has to move upward]
The binary of $0B is 00001011 and taking 2s complement of 00001011 is 11110101 i.e $F5 . \"To calculate the displacement we modify the PC by adding an immediate twos complement value\"
b ) Reason why we multiply by 4 i.e We can calculate 16s complement by doing it easier way. Taking the same example -$0B . Substrct both the Hex value by $F ($F -0 ) & ($F -B ) +1 = $F5.
Comes out to be $F5 .
Thanks, I hope it clarifies. Let me know if there is anything.
