I'm reading a book of David Patterson and John Hennesy titled: Computer Organization and Design. In the RISC-V architecture set which the book is about there are two instruction formats related to jumping - SB-type and UJ-type. The former uses 12
-bit constant to represent offset (in bytes) to jump from the current instruction and the latter uses 20
-bit constant to represent the same. Then the author says the following:
Since the program counter (PC) contains the address of the current instruction, we can branch (SB-type) within
+=2^10
words of the current instruction, or jump (UJ) within+= 2^18
words of the current instruction, if we use thePC
as the register to be added to the address.
I don't understand how they get those 2^10
and 2^18
. Since the constant the instructions use is two's complement, then it can represent values from -2^11
to 2^11 - 1
in the first case and -2^19
to 2^19 - 1
in the second case. Since these constants represent bytes, but we want to know how many words we can jump over, therefore we need to divide max value of bytes by four, so the max which we can get is 2^11 / 2^2 = 2^9
words in the first case and 2^17
in the second one.
Could someone please take a look at my calculations above and point me out to what I'm missing and what's wrong with my calculations and thoughts?
UPDATE:
Probably I didn't understand the author correctly. May it be the case that they mean the lower-bound (-2^10
) and upper-bound (+2^10
)? So they mean that we can never jump beyond 2^10
from the current instruction?