void main(){
int n,i,sum; // assume that $s0 is for n, $t0 for i and $s1 for sum
/* MIPS code for reading an integer. */
addi $v0, $zeros, 5
syscall
add $s0, $zeros, $v0
/*---------------------------------------------*/
// mainly translate the following code into MIPS code
sum=0;
for (i=1; i<=n; i++)
sum+=i;
/* MIPS code for printing an integer */
addi $v0,$zero,1
add $a0,$zeros,$s1
syscall
/*--------------------------------------------*/
addi $v0,$zeros,10
syscall
/*---------------------------------------------*/
}
共2条
1/1 1 跳转至页
用Mars 寫一MIPS 組合語言讀入一正整數n,計算並列印1+2…+n的和。

addi $v0, $zero, 5
syscall
add $s0, $zero, $v0
# mainly translate the following code into MIPS code
#sum=0;
#for (i=1; i<=n; i++)
#sum+=i;
li $t1, 0 #i
li $s1, 0 #sum
for_1: #for
add $t1, $t1, 1#i++
add $s1, $s1, $t1#sum+=i;
bne $t1, $s0, for_1#i<=n
addi $v0,$zero,1
add $a0,$zero,$s1
syscall
addi $v0,$zero,10
syscall
共2条
1/1 1 跳转至页
回复
打赏帖 | |
---|---|
【STM32F769】AI之与本地deepseek对接被打赏50分 | |
Buck电路工作在CCM模式下电感电流的计算公式是什么?被打赏5分 | |
buck电路工作原理被打赏5分 | |
基于MSPM0L1306的MODBUS-RTU协议通讯实验被打赏100分 | |
我想要一部加热台+多合一调试工具被打赏18分 | |
每周了解几个硬件知识+485硬件知识分享被打赏10分 | |
【换取手持数字示波器】树莓派PICO调试器官方固件本地化部署实践被打赏24分 | |
【换取手持数字示波器】分享一个KEIL无法识别CMSIS-DAP调试器的解决办法被打赏20分 | |
【换取手持数字示波器】分享一个自制的ArduinoNano扩展板底板被打赏23分 | |
【换取手持示波器】树莓派PICOW网页烟花被打赏18分 |