Reputation: 350
I'm trying to understand the range of each branch instruction.
The beq
and bne
instruction do something like that :
PCnew = (PCold + 4) + (steps from branch point)*4
However the jump instruction does not add 4 to the PCold, although i know that every mips instruction add 4 (to go to next instruction). So if i write :
j loop
Then the PCnew takes the address of loop*4 and does not add four to it.Why is that? Am i getting something wrong ?
Upvotes: 2
Views: 1424
Reputation: 213170
Jumps use absolute addresses, while branches use PC-relative addresses.
So a jump just sets the PC to the jump destination address.
For a branch though, the branch displacement (aka offset) is added to the PC. However the PC has already been advanced to the next instruction at this point, so the branch destination address is: <address of branch instruction> + 4 + <relative displacement>
.
Upvotes: 2