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 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |