1. | Write the full 32-bit jump address: 0x00400000 | 0000 0000 0100 0000 0000 0000 0000 0000 |
2. | Write the 26-bit field of the jump instruction: | 00 0001 0000 0000 0000 0000 0000 |
3. | Shift it left two positions: | 0000 0100 0000 0000 0000 0000 0000 |
4. | What are the high-order four bits of the PC? | 0000 |
5. | Copy (4) to the left of (3): | 0000 0000 0100 0000 0000 0000 0000 0000 |
6. | Is (5) the same as (1)? | Yes |
How do you know what the high-order four bits of the PC are? Well, since you have the address of the jump instruction, you know that its address is in the PC. So the high order four bits come from that address.
With some trickery, a 26-bit field can specify a 32-bit address. But it is a nuisance to figure out! If you were doing machine language programming, that is what you would have to do. But the assembler does the work for you. Here is a tiny program:
## jump.asm ## .text .globl main main: sll $0,$0,0 sll $0,$0,0 sll $0,$0,0 sll $0,$0,0 j main addiu $8,$8,1 ## End of file
It is similar to the previous example.
The symbolic address main
stands for the address of the first instruction.
The instruction
j main
tells the assembler to assemble a machine
instruction with the proper 26-bit field
so that control is transfered to main
.
The branch delay slot is filled with an instruction that increments register $8.