Reputation:
.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
Upvotes: 0
Views: 503
Reputation: 26
you didn't read the numbers from the console and store them in registers. Fixed your code and it should be working now. Added comments for you to understand.
.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
Upvotes: 1