整数求和的汇编程序
Assembly Program for summing integers
基本上我正在编写一个程序,将输入的数字总和相加。这是我的代码,它在 main 下给我一个错误。如果你 post 一个答案并找到什么错了,你能帮忙贴出新代码吗??谢谢.. 编辑:ERROR MESSAGE
error spim: (parser) Label is defined for the second time on line 5 of the file C:/Users/peter/Desktop/Running Sums.asm main
.data
str: .asciiz "Enter a integer:"
str2: .asciiz "Sum ="
.text
main:
li $a0,0 #sum = 0
loop:
li $v0,4 #print string
la $a0,str
syscall
li,$v0,5 #Take input
syscall
beq $v0,[=10=],done #if zero was input end and display sum
add $v0,[=10=],$v0 #sum = sum + input
j loop #Jump to input another number
done:
li $v0,4 #print string
la $a0,str2
syscall
li $v0,1 #print sum
move $a0,$s0
syscall
.end
正确的工作代码是:
.data
str: .asciiz "Enter a integer:"
str2: .asciiz "Sum ="
.text
main:
li $s0,0 #sum = 0
loop:
li $v0,4 #print string
la $a0,str
syscall
li $v0,5 #Take input
syscall
beq $v0,[=10=],done #if zero was input end and display sum
add $s0,$s0,$v0 #sum = sum + input
j loop #Jump to input another number
done:
li $v0,4 #print string
la $a0,str2
syscall
li $v0,1 #print sum
move $a0,$s0
syscall
.end
要么书错了,要么你抄错了
基本上我正在编写一个程序,将输入的数字总和相加。这是我的代码,它在 main 下给我一个错误。如果你 post 一个答案并找到什么错了,你能帮忙贴出新代码吗??谢谢.. 编辑:ERROR MESSAGE
error spim: (parser) Label is defined for the second time on line 5 of the file C:/Users/peter/Desktop/Running Sums.asm main
.data
str: .asciiz "Enter a integer:"
str2: .asciiz "Sum ="
.text
main:
li $a0,0 #sum = 0
loop:
li $v0,4 #print string
la $a0,str
syscall
li,$v0,5 #Take input
syscall
beq $v0,[=10=],done #if zero was input end and display sum
add $v0,[=10=],$v0 #sum = sum + input
j loop #Jump to input another number
done:
li $v0,4 #print string
la $a0,str2
syscall
li $v0,1 #print sum
move $a0,$s0
syscall
.end
正确的工作代码是:
.data
str: .asciiz "Enter a integer:"
str2: .asciiz "Sum ="
.text
main:
li $s0,0 #sum = 0
loop:
li $v0,4 #print string
la $a0,str
syscall
li $v0,5 #Take input
syscall
beq $v0,[=10=],done #if zero was input end and display sum
add $s0,$s0,$v0 #sum = sum + input
j loop #Jump to input another number
done:
li $v0,4 #print string
la $a0,str2
syscall
li $v0,1 #print sum
move $a0,$s0
syscall
.end
要么书错了,要么你抄错了