Search code examples
mips32

What will be the offset value and what will be the address of beq instruciton?


The first instruction is at ‘0’ location in instruction memory.

Label:
lw $t0,8($t1)
add $t3,$t2,$t0
beq $t3,$t4,Label
jump Label

Suppose values of reg $t3 and reg $t4 are equal and it will jump to Label address. So, I want to ask what will the offset value of Label and what will be the address of beq instruction?


Solution

  • The beq instruction is 3 instructions after Label(which has address 0000). So the beq is at 4*3 = 12 + 0000 = 0012 address.

    You say $t3 == $t4, so offset says to the assembler to go 4 instructions back, so:

    PCnew = (PCold + 4) + Label * 4

    PCold is 0016 and Label is -4 , so PCnew equals 0000 and goes back to Label:

    In instruction j Label the Imm26 (26bits), has the address of Label divided by 4 ... so technically 0000. After jump instruction :

    PCnew = (Label*4) = (0000)*4 = 0000