Understanding the Jump Instruction

advertisement
Understanding the Jump Instruction
The implementation of the jump instruction and how MIPS constructs the jump-toaddress leads to an interesting understanding about how MIPS works. We know that the
jump-to-address is constructed in the following way:
1. We take the immediate address in the jump instruction itself, which is the 26
lower order bits from the Jump instruction itself.
2. We shift this immediate address of 26 bits by two bits to make it 28 bits; bythe-way this can be thought of as concatenating 2 zero bits to the lower order
end of the 26 bits. This is equivalent to multiplying the 26 bit binary number
by 4.
3. Then we take the upper order 4 bits of the PC, which has already been updated
to reflect the next instruction address in sequence, and concatenate these 4 bits
on to the higher order – left end – of the 28 bits to give the 32 bit binary
number, which is now the jump address.
This is clearly explained in our text. But the real deeper question is why do we do this
and what is the implication or what assumptions about MIPS makes this work. The first
two steps are fairly straight forward. For example, the shifting in step two, in fact
implements the multiplying of the 26 bit address by 4, since the immediate address is in
terms of words and we need the address in terms of bytes for the MIPS machine.
But it is the last step, or third step, that is not self evident. We can explain it this way. In
MIPS we consider a fully addressable memory space of 232 bytes. Let us suppose that
memory is subdivided into 16 blocks of 228 bytes each, which is (28)*(220) bytes= 256
MB = 64 MWords of 32 bits. Now each block is named by a four bit address <xxxx>, so
there will be the 16 blocks <0000>, <0001>, <0010>, …<1111> . The actual addresses
within a block will all be 32 bits long and all will start at the higher order end with what
we have called the 4 bit block address and the lower order 28 bits will be any number
between zero and (228)-1. Thus the actual addresses within lets say block <0101> will be
32 bit long and all start with 0101 in the bits [31-28].
The MIPS compiler is forced to put a program within one block only, so that all
statements within a program will be in actual 32 bit addresses that start with the block
address.
Now a jump instruction is considered to use pseudo-direct addressing in our book. This is
so because the immediate address multiplied by 4 is the actual address in a block so it is
direct addressing within the block of up to 228 addresses. It is pseudo, that is not true
direct addressing, because we need to add on to the address the block address. It could as
easily been called pseudo-relative addressing since the immediate address (multiplied by
4) <yyyy…y> of 28 bits is being added to the address of the first byte in the block
<xxxx> which has the actual 32 bit address of <xxxx000…0> to give the address
<xxxxyyy…y> of 32 bits. Note that the immediate address must be positive since it is a
cosc2021 M. Mandelbaum Oct. 19, 2003
real address within a block and not an offset in the normal way and thus it is not a signed
number as it is in the branch or load and store instructions.
Now the .text portion of our program is all put into one block of memory as described
above by the rules of MIPS. However, if we use two text portions in our program then it
is possible that MIPS may put one in one block and the other in another block of
memory.
cosc2021 M. Mandelbaum Oct. 19, 2003
Download