客观的:根据用户输入,使用五个寄存器查找平均值。
Example:1 3 2 9 4
Output: 3
输出是 3,因为 3.8 是小数,我希望它是整数
我的目标是不使用数组,但我在添加所有 5 个寄存器时遇到问题:
.data
prompt1: .asciiz " Please enter an integer: "
prompt2: .asciiz " Please enter an integer: "
prompt3: .asciiz " Please enter an integer: "
prompt4: .asciiz " Please enter an integer: "
prompt5: .asciiz " Please enter an integer: "
result: .asciiz "The average is: "
.text
main:
#t0 - hold prompt1
#t1 - hold prompt2
#t2 - hold prompt3
#t3 - hold prompt4
#t4 - hold prompt5
#t5 - hold sum from prompt1 to prompt5
#t6 - hold the average value
# Prompt the user to enter integer1.
li $v0, 4 # syscall to print string
la $a0, prompt1
syscall
# Read integer1
li $v0, 5 # syscall to read an integer
syscall
move $t0, $v0 # move number to read into $t0
# Prompt the user to enter integer 2.
li $v0, 4
la $a0, prompt2
syscall
# Read integer2
li $v0,5
syscall
move $t1, $v0
# Prompt the user to enter integer 3.
li $v0, 4
la $a0, prompt3
syscall
# Read integer3
li $v0,5
syscall
move $t2, $v0
# Prompt the user to enter integer 4.
li $v0, 4
la $a0, prompt4
syscall
# Read integer4
li $v0,5
syscall
move $t3, $v0
# Prompt the user to enter integer 5.
li $v0, 4
la $a0, prompt5
syscall
# Read integer5
li $v0,5
syscall
move $t4, $v0
我遇到错误的部分
# add all integers to $t5
add $a0, $t0, $t1, $t2, $t3, $t4
li $v0, 1
syscall
继续...
# Read the sum
li $v0, 5
syscall
move $t5, $v0
# Divide Sum / count
div $t5, 5
# retrieve it
mflo $t6
#print out the average
move $a0, t6
li $v0, 1
la $a0, result
syscall
exit:
li $v0, 10
syscall
我收到一条错误消息
spim:(解析器)第71行存在语法错误...'add $a0, $t0, $t1, $t2,
$t3,$t4