我正在尝试将C代码转换为MIPS汇编代码,但是我收到错误:
"$t4": operand is of incorrect type
我找不到错误。这是我的C代码和汇编代码:
int A[4];
int i;
int diff;
for(i=0; i<3; i++){
diff = A[i+1] - A[i];
if (diff > 0)
A[i] = 5*A[i];
else
A[i+1] = -5*A[i];
}
MIPS代码:
.data
intArr: .word 2, 4, 6, 8
.text
main:
la $s3, intArr # address of start of intArr $t1
li $s0, 0 # load loop iteration variable (i) to $s0
li $t2,3 # constant $t2 = 3
Loop:
bge $s0,$t2 end # end program when 3 iterations happened
# diff = intArr[i+1] - intArr[i]
lw $t1,intArr($s3) # $t1=intArr[i]
addi $t3, $s3,4 # intArr[i + 1]
lw $t4,intArr($t3) # $t4 = intArr[i + 1]
sub $t5, $t4,$t1 # diff = $t4 - $t1
bgt $t5,0,else #check if diff($t5) > 0
addi $t6,$zero,$t4
addi $t6,$t6,$t4
addi $t6,$t6,$t4
addi $t6,$t6,$t4
sw $t6,intArr($s3)
else:
subi $t6,$t4,$zero
subi $t6,$t4,$t4
subi $t6,$t4,$t4
subi $t6,$t4,$t4
subi $t6,$t4,$t4
subi $t6,$t4,$t4
subi $t6,$t4,$t4
sw $t6,intArr($s3)
addi $s3, $s3,4 #next element A[i+1]
addi $s0, $s0, 1 #Add immediate value 1 to i (i++)
j Loop #Jump back to the top to loop again
end:
li $v0,10
syscall