【发布时间】:2009-04-18 01:27:29
【问题描述】:
编写一个 MIPS 程序,生成从 1 到 100 的所有偶数并将其相加。
- 它必须至少有一个循环
- 它应该将总和存储在寄存器 R12 中
这就是我写的:
main:
li $t0, 0 # clear register $t0 to zero
li $t4, 0 # clear register $t4 to zero
loop:
add $t0, $t0, 2 # generating even numbers in register $t0
add $t4, $t4, $t0 # compute the sume
bne $t0, 100, loop # if t0 reached 100 then go to loop.
b endloop # branch to endloop
endloop:
li $v0, 10 # terminate program run and
syscall # Exit
这是正确的吗?
【问题讨论】:
-
你能运行它吗?你有 MIPS 板或模拟器之类的吗?
-
我使用 gxemul 来模拟运行 NETBSD 的 mips 架构 en.wikipedia.org/wiki/GXemul
-
另一个模拟器是qemu,它模拟了包括MIPS在内的一堆架构和系统。
-
谢谢...但是你能帮我一个忙吗,我用 spim 运行它,但一切看起来都不错,可以帮助我用任何模拟器运行它,看看我是否正确...谢谢
-
@csunwold,我认为寄存器 R12 是通用寄存器编号 12,恰好是 $t4