我正在尝试将下面的 C 代码翻译成 MIPS 汇编语言,但我对其中的大部分内容有所了解,但我不知道汇编中第一行的等价物是什么......
int ary[3] = {2,3,4};
如果有人可以查看我的 C 来组装“翻译”并验证我是否走在正确的轨道上,我将不胜感激。
C代码
int ary[3] = {2,3,4};
int i=0;
//loop to double array values
for(i=0; i < 3; i++){
ary[i] = ary[i]*2;
}
我尝试了什么:
add $t0, $s0, $zero #get base address of the array 'ary' (dont understand this part)
addi $t1, baseAddress, 8 #cut off point to stop the loop; array[2]
addi $t1, $zero, $zero #initialize i=0
Start:
lw $t2, base(offset)
sll $t2, $t0, 1 #mutiply $t2 by 2
sw $t2, base(offset)
addi $t0, $t0, 4 # Increment the address to the next element
bne $t0, $t1, Start # $t0 will keep increasing until reaches stopping point $t1
Exit: