这个解决方案中的错误是什么 [英] what is the error in this solution
本文介绍了这个解决方案中的错误是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
程序计算从1到n的整数之和,用户应保持输入整数,直到输入0
program to compute the sum for an integer from 1 to n ,the user should keep enter integers until enter 0
# i..>$t0 sum...>$t1 n...>$t2
.data
prompt1: .asciiz "Enter a number"
prompt2: .asciiz "The sum of entered number is: "
.text
main:
li $v0, 4 #System call code for print String
la $a0, prompt1 #load address of prompt1
syscall #Call OS to print prompt1
li $v0, 5 #System call code for read integer
syscall #Call OS to read integer into $v0
move $t2, $v0 #move the number to read into $t2
addi $t0, $zero,1 #i=0+1
add $t1, $zero,$zero #sum=0+0
loop: slt $t3, $t2,$t0 #t4= if n(i)
bnq $zero, $t3, goo #if 0==t4 go to "goo"
add $t1, $t1, $t0 #sum=+1
addi $t0, $t0, 1 # i+=1
j loop
goo: beq $t2, $zero, exit #if n==0 go to "go"
li $v0, 4
la $a0, prompt2
syscall # print out "Sum = "
li $v0, 1
move $a0, $t1
syscall # print out actual sum
exit:
li $v0, 10
syscall
推荐答案
t0 sum ...>
t0 sum...>
t1 n ...>
t1 n...>
t2
.data
prompt1:.asciiz输入数字
prompt2:.asciiz输入数字的总和为:
.text
main:
li
t2 .data prompt1: .asciiz "Enter a number" prompt2: .asciiz "The sum of entered number is: " .text main: li
这篇关于这个解决方案中的错误是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文