I am reading the book 'Computer Organization and Design' by Patterson and Hennessy and got interested in MIPS.
I have doubts in finding the range of a jump/branch instruction. Also in determining the number of branch/jump instructions required to get to a specific address.
Can someone provide an explanation of how this has to be calculated i.e. Considering PC at a specific address and finding the number of branch/jump instructions needed to go to a different address? For example, what if PC is at 0x10001010, what is the range of addresses of branch and jump instructions?
Or can you direct me to some online resource or book which would help me in getting a better understanding of these?
That means the j instruction can jump to any absolute address that can be created from the operation above. The largest value for target , therefore, is 226-1 (0x03FFFFFF), and the highest reachable address is (PC & 0xF0000000) | 0x0FFFFFFC .
Jump Instruction The jump instructions load a new value into the PC register, which stores the value of the instruction being executed. This causes the next instruction read from memory to be retrieved from a new location.
The difference is that the target address for JR comes from a register specified in the instruction. The jump-and-link instruction ( JAL ) behaves like the simple jump instruction ( J ), but also stores a return address in register 31 ($ra).
The following is all for MIPS-32.
Branch B, BEQ, BNE, etc.
instructions have a 16 bit signed word offset field, allowing a branch to an address +/- 128kBytes from the current location. A jump J
instruction specifies an address within the current 256MByte region specified by PC's most significant 4 bits : 26<<2 bits(this is not a relative address). To branch to an arbitrary address anywhere in the 4GB address space, use JR
(jump register) which jumps to an address contained in a general purpose register.
It takes either a single branch or jump instruction, or a register load followed by a JR
to jump to an arbitrary address, depending how far away the address is.
The best book for MIPS programming is still See MIPS Run. You can also find MIPS architecture reference manuals at mips.com (registration required). The most relevant document is MIPS32® Architecture for Programmers Volume II: The MIPS32® Instruction Set.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With