我有下面的代码,它有效地应该从1-6增加,同时做一个变量的算术。Mips循环迭代
用C的一个例子是
int res = 0;
for(i=1; i<6; i++) {
res += i*i+1;
}
现在对于我的MIPS代码:
.data
res: .word 0
.text
li $t0, 1 #int j = 1
loop:
beq $t0, 6, end #for(int j = 1; j < 6; j++)
add $t0, $t0, 1
mul $t1, $t0, $t0 #res += j * j + 1
addi $t1, $t1, 1
sw $t1, res
b loop
end:
li $v0, 1 #checking the end result
la $a0, res
syscall
li $v0, 10 #graceful exit
syscall
出于某种原因,导致我走向到底得的是约300万,这显然是错误的。有没有人看到这个问题是什么?我相当新的mips组装。
谢谢
什么是C代码中的j?你的意思是我吗? – BlackBear
是的,我做了,我改了它 – user3183230