Reputation: 31
Try to study Mips from the book Computer organization and design by David A Patterson. 4th edition.
However for one of the question regarding PC-Relative Address, I get confuse,
Question is:
Current PC is 0x00000600
, can you use a single batch instruction to get to the PC address as
a) 1010 1101 0001 0000 0000 0000 0000 0010
b) 1111 1111 1111 1111 1111 1111 1111 1111
From the answer is for the current PC the range is:
0X0604 + 0x1FFFC = 0x0002 0600
to 0x0604 - 0x20000 = 0xFFFE
How do they get the 0x1FFFC and 0X20000 ?
Please help, many thanks in advance.
Upvotes: 1
Views: 5114
Reputation: 135
The Branch instructions in the MIPS architecture lets you specify a 16 bit 2s complement offset which is shifted to the left by two bits to make a 18 bit PC offset (since the instructions have to be byte aligned the lowest 2 bits always have to be a zero) and is then added or subtracted from the PC.
Now if you would take the maximum PC offset value you can add to the PC (so that you end up adding to the PC using 2s complement) with the shifting considered it would be 00000000000000011111111111111100 or 0x1FFFC.
And if you take the maximum PC offset Value you can subtract to the PC (so that you end up subtracting to the PC using 2s complement) with the shifting considered it would be 00000000000000100000000000000000 or 0x20000.
Thus if you have a PC value and you want to know what the range of addresses it can jump to, you just need to find the maximum value and the minimum value which is PC + 0x1FFFC and PC - 0x20000 respectively.
Feel free to ask any questions if you are confused about anything.
Upvotes: 3