【发布时间】:2015-10-18 20:34:12
【问题描述】:
我正在研究关于课程计算机体系结构的问题,我应该在其中将一些 C 代码转换为 Mips。
int A[52], B[52];
2 for (j = 1; j < 52 ; j++)
3 for (i = j; i < 52; i++) {
4 B[i] = B[i-1] + A[j] ;
5 }
我的翻译如下。我认为 addi 等于 li 但我不知道 li 的真正含义,所以我使用 addi 让我添加一个常量。假设数组 A 保存在 $s0 中,B 保存在 S$1
addi $t1, $0, 1 //setting j to 1
addi $t2 , $t1 , 0 //setting i (which is always equal to j)
addi $t6, $t1 , -1 //this will be used for writing B[i-1]
addi $t3, $0, 50 //making a temp value 50 to end the loop.
Loop:
beq $t3, $t1,end //when j becomes 50 end the loop.
beq $t3, $t2,end //when i becomes 50 end the loop.
lw $t4 , $s0 //loading A
lw $t5, $s1 //loading B
add 4$t1($t5), 4$t6($St5),4$t2($t4) //This is the part I think I am doing it //wrong.I want to write 4($t5)for first element 8 for second an so on but I dont //know how to do it.Is this a legit way?
sv $t5, $s1 //storing B
addi $t1, $t1, 1 //increment j by one.
addi $t2,$t2,1 //increment i by one
j loop:
end
我的问题如下。是否有任何宇宙我可以添加这样的数组,如果没有我怎么能。另外我无法检查我的答案,因为这本书没有解决方案。我做其他操作的方式是正确的?
【问题讨论】:
标签: arrays assembly dynamic mips