0
我運行在MARS仿真以下MIPS代碼:解碼BNE MIPS指令
add $t0, $zero, $zero # i = 0
add $t4, $zero, $zero # initialize the sum to zero
add $t5, $zero, $zero # initialize temporary register to zero
la $a0, array # load address of array
la $a1, array_size # load address of array_size
lw $a1, 0($a1) # load value of array_size variable
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
add $t5, $a0, $zero # save contents of $a0 in temporary reg $t5
nop # done.
在機器代碼中,bne
指令如下:00010101011000001111111111111001
。在這種情況下,立即數是:1111111111111001
,等於:0xFFF9
。 MIPS將採取這一點,將它左移2(將其乘以4),並將其程序計數到該數字。但是,0xFFF9
乘以4即爲0x3FFE4
。這怎麼可能?程序計數器SLL
應該是0x18而不是0x3FFE4
。我在這裏錯過了什麼?
謝謝
即時簽署因此fff9是-7 – user786653
這是一個偏移量,而不是新PC的值 – harold