我在下面的代碼中有幾個MIPS指令的問題
1. addi
是一個算術指令,它的目的是什麼?
2.爲什麼j
和beq
之後有單個nop
,但addi
之後有多個nop
?
謝謝!關於MIPS指令在代碼中的問題
if(a==b) x=3; /* simple C code */
else x=4;
y=5;
lw $1,a # possible unoptimized assembly language
lw $2,b # no ($0) shown on memory access
nop # wait for b to get into register 2
nop # wait for b to get into register 2
beq $1,$2,lab1
nop # branch slot, always executed *********
addi $1,4 # else part
nop # wait for 4 to get into register 1
nop # wait for 4 to get into register 1
sw $1,x # x=4;
j lab2
nop # branch slot, always executed *********
lab1: addi $1,3 # true part
nop # wait for 3 to get into register 1
nop # wait for 3 to get into register 1
sw $1,x # x=3;
lab2: addi $1,5 # after if-else, always execute
nop # wait for 5 to get into register 1
nop # wait for 5 to get into register 1
sw $1,y # y=5;
感謝您的詳細解釋。我研究過MIPS ISA,發現'addi'有兩個寄存器。所以教官的例子沒有意義。謝謝 ! – newprint