... stretches the distance of the branch by having PC-relative addressing refer to the number of words to the next instruction instead of the number of bytes.
This sentence only means:
The instruction 0x1000nnnn (b nnnn
) stored at the address X will jump to the instruction at the address X+4+4*nnnn
, not to the instruction at the address X+4+nnnn
.
The sentence says nothing about the PC register and its value itself.
I observed that the $pc
register doesn't follow that rule and has always the byte memory address stored.
Shouldn't the $pc
register be something like this before the execution of the below instructions located in the instruction addresses?
The question here is: What exactly is the $pc
register?
On some CPUs (like ARM), there are instructions that would be written as addu $t0,$t0,$pc
in MIPS assembly language. Talking about such CPUs it is easy to answer the question:
The value of the $pc
register is the value which will be added to $t0
if the instruction addu $t0,$t0,$pc
is executed.
On real MIPS CPUs (not MIPS emulators), the PC register is some kind of memory (a 30-bit latch) which can hold 30 bits of information.
However, when talking about information stored in some memory, we have to define how to interpret the information:
The bits 10000111
may be interpreted as 135 (unsigned), 87 (BCD), -121 (two's complement), -120 (one's complement), -7 (sign and absolute), SOME_ENUM_CONSTANT
(enumeration), -0.09, 0.7, 1.35 (various floating- and fixed-point variants) ...
It is well defined that the bits 0000...011100
in the PC register point to the instruction at address 0x70. However, it is not defined if this value has to be written as PC=0x1C
or as PC=0x70
.
Therefore some MIPS emulator might display $pc=0x400000
and another one might display $pc=0x100000
for the same value in the PC register!
However, I think (nearly) all MIPS emulators will display $pc=0x400000
because the users are interested in the address the instruction points to.