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 跳转至页
回复
打赏帖 | |
---|---|
VOFA+波形显示+JYD-31蓝牙发送和解析不定长数据被打赏10分 | |
宏定义和const关键字定义被打赏5分 | |
换取逻辑分析仪】STM32G4从入门到大师之五:ADC中断方式单路采集电压被打赏16分 | |
【换取逻辑分析仪】STM32G4从入门到大师之四:ADC查询方式单路采集电压被打赏14分 | |
【分享开发笔记,赚取电动螺丝刀】几个单片机I2S外设的BLCK时钟对比被打赏20分 | |
【功率监测与控制系统DIY活动成果贴】DIY功率计与LabVIEW数据采集被打赏100分 | |
【分享开发笔记,赚取电动螺丝刀】使用ESP32S3调试I2S音频模块MAX98357被打赏22分 | |
【Freertos】任务管理被打赏10分 | |
分享博世的两种不同的喷射系统模式被打赏5分 | |
汽车+开路实验与短路实验被打赏10分 |