我正在尝试打印从用户那里获取的三个数字的总和和平均值。程序 运行 不正确
I'm trying to print sum and average of three numbers taken from user. Program's not running properly
.data
prompt: .asciiz "Enter number 1: "
prompt2: .asciiz "Enter number 2: "
prompt3: .asciiz "Enter number 3: "
newline: .asciiz "\n"
fnum: .asciiz "Average is: "
snum: .asciiz "Sum is: "
.text
.globl main
main:
li $v0, 4
la $a0, prompt
syscall
li $v0, 5
syscall
move $t1, $v0
li $v0, 4
la $a0, prompt2
syscall
li $v0, 5
syscall
move $t2, $v0
li $v0, 4
la $a0, prompt3
syscall
add $t4,$t1,$t2
add $t4,$t4,$t3
li $v0, 4
la $a0, snum
syscall
move $a0, $t4
li $v0, 1
syscall
li $v0, 4
la $a0, newline
syscall
li $t5,3
div $t6, $t4,$t5
move $a0, $t6
li $v0, 1
syscall
你没有从控制台读取数字并将它们存储在寄存器中。修复了您的代码,它现在应该可以工作了。加了评论,方便大家理解。
.data
prompt: .asciiz "Enter number 1: "
prompt2: .asciiz "Enter number 2: "
prompt3: .asciiz "Enter number 3: "
newline: .asciiz "\n"
fnum: .asciiz "Average is: "
snum: .asciiz "Sum is: "
.text
.globl main
main:
li $v0, 4
la $a0, prompt #prompt for first number
syscall
li $v0, 5
syscall
move $t1, $v0 #read number from console and store in $t1
li $v0, 4
la $a0, prompt2 #prompt for first number
syscall
li $v0, 5
syscall
move $t2, $v0 #read number from console and store in $t2
li $v0, 4
la $a0, prompt3 #prompt for first number
syscall
li $v0, 5
syscall
move $t3, $v0 #read number from console and store in $t2
add $t4,$t1,$t2
add $t4,$t4,$t3
li $v0, 4
la $a0, snum #sum string printing
syscall
move $a0, $t4
li $v0, 1 #print sum value
syscall
li $v0, 4
la $a0, newline #print newline string
syscall
li $t5,3
div $t6, $t4,$t5
li $v0, 4
la $a0, fnum #print average string
syscall
move $a0, $t6
li $v0, 1 #print average value
syscall
li $v0, 10
syscall
.data
prompt: .asciiz "Enter number 1: "
prompt2: .asciiz "Enter number 2: "
prompt3: .asciiz "Enter number 3: "
newline: .asciiz "\n"
fnum: .asciiz "Average is: "
snum: .asciiz "Sum is: "
.text
.globl main
main:
li $v0, 4
la $a0, prompt
syscall
li $v0, 5
syscall
move $t1, $v0
li $v0, 4
la $a0, prompt2
syscall
li $v0, 5
syscall
move $t2, $v0
li $v0, 4
la $a0, prompt3
syscall
add $t4,$t1,$t2
add $t4,$t4,$t3
li $v0, 4
la $a0, snum
syscall
move $a0, $t4
li $v0, 1
syscall
li $v0, 4
la $a0, newline
syscall
li $t5,3
div $t6, $t4,$t5
move $a0, $t6
li $v0, 1
syscall
你没有从控制台读取数字并将它们存储在寄存器中。修复了您的代码,它现在应该可以工作了。加了评论,方便大家理解。
.data
prompt: .asciiz "Enter number 1: "
prompt2: .asciiz "Enter number 2: "
prompt3: .asciiz "Enter number 3: "
newline: .asciiz "\n"
fnum: .asciiz "Average is: "
snum: .asciiz "Sum is: "
.text
.globl main
main:
li $v0, 4
la $a0, prompt #prompt for first number
syscall
li $v0, 5
syscall
move $t1, $v0 #read number from console and store in $t1
li $v0, 4
la $a0, prompt2 #prompt for first number
syscall
li $v0, 5
syscall
move $t2, $v0 #read number from console and store in $t2
li $v0, 4
la $a0, prompt3 #prompt for first number
syscall
li $v0, 5
syscall
move $t3, $v0 #read number from console and store in $t2
add $t4,$t1,$t2
add $t4,$t4,$t3
li $v0, 4
la $a0, snum #sum string printing
syscall
move $a0, $t4
li $v0, 1 #print sum value
syscall
li $v0, 4
la $a0, newline #print newline string
syscall
li $t5,3
div $t6, $t4,$t5
li $v0, 4
la $a0, fnum #print average string
syscall
move $a0, $t6
li $v0, 1 #print average value
syscall
li $v0, 10
syscall