I have a set of instructions as follows:
loop:
sll $t1, $t0, 2 # t1 = (i * 4)
add $t2, $a0, $t1 # t2 contains address of array[i]
sw $t0, 0($t2) # array[i] = i
addi $t0, $t0, 1 # i = i+1
add $t4, $t4, $t0 # sum($t4) = ($t4 + array[i])
slt $t3, $t0, $a1 # $t3 = ( i < array_size)
bne $t3, $zero, loop # if ( i < array_size ) then loop
The sll instruction has an address (program counter) of 0x18. bne has an address of 0x30. MARS Simulator interprets the bne instruction as: bne $11, $0, 0xfff9. 0xfff9 is -7, meaning the instruction will jump 7 steps back. However, sll is six steps back. Does MIPS take into account the current instruction? Or does this happen because the program counter is incremented in the fetch stage, before the instruction finishes executing?