branch if not equal to PC address

527 views Asked by At

Hey got a question regarding Branch instructions.

I have a branch if not equal to instruction located at 0x00002000 (PC) and the following:

RS(Register 4) = 0 RT(Register 3) = 7

Therefore branch does not equal and should then follow the following equation:

if (rs!=rt) goto (PC+offset)

The PC is 0x00002000 and the offset is 0000000000001000

What I have done is converted the offset to 32 bits which will just have an extra 16 0's to the left but I have no idea how to add the two and the lecture slides aren't particularly clear or give examples on how to do this... So I was just wondering how i could do this to get the new PC?

Any help is much appreciated, Thanks!

Dan

1

There are 1 answers

0
Danny On

The new PC will be the address of the instruction AFTER your branch instruction, plus the offset.

So in this case, if the branch instruction is 4 bytes, and the offset is 0x1000, then the new PC will be 0x3004 after the branch instruction executes.

Here is a wikipedia entry on PC-relative addressing http://en.wikipedia.org/wiki/Addressing_mode#PC-relative