2
votes
repeat : lw $v1, 1($a0)

         add $v0, $v0, $t0
         sw $v1, 1($a1)
         addi $a1, $a1, 1
         addi $a1, $a1, 2
         addi $a2, $a2, 1
         addi $a0, $a0, 3
         bne $v1, $zero, repeat

How do I know that the 16 bit address field of the last instruction i.e bne $v1, $zero, repeat is -8 in decimal form? The 32 bit machine code for this instruction is given below. This was a preparation question whose solutions were given to us but I don't understand how to write the binary equivalent of the repeat label.

bne      $v1      $zero         repeat

000101   00011     00000     1111111111111000
1

1 Answers

1
votes

Because the address of the label is 7 words before the branch instruction, and +1 because MIPS increments the PC immediately after fetching the current instruction (due to pipelining), hence the offset is -8.