Write a MIPS program to solve the following problem a Prompt

Write a MIPS program to solve the following problem: a. Prompt the user to enter 3 integer values. b. Read the integer. c. Calculate and print the average of the integers as an integer result. d. Calculate and print the average of the integers as a floating point number. The number of decimal places is not relevant in your answer

***no Pseudo-instructions allowed***

This is what I have so far:

.data
data:.word 0,0,0
prompt: .asciiz \"Enter 3 integers\ \"
newline: .asciiz \"\ \"

.text
   ori $v0,$0,4 # Command to print string
   lui $a0,0x1001 # Sets register for data
   addiu $a0,$a0,12 # Get start of prompt
   syscall # Print the prompt
  
   ori $v0,$0,5 # Command to read integer
   syscall # Value in $v0
   lui $t0,0x1001 # Sets register $t0
   sw $v0, 0($t0) # Stores value of first integer
  
   ori $v0,$0,5 # Command to read integer
   syscall # Value in $v0
   lui $t1,0x1001
   sw $v0, 4($t1) # Stores value of second integer
      
   ori $v0,$0,5 # Command to read integer
   syscall # Value in $v0
   lui $t2,0x1001
   sw $v0, 8($t2) # Stores value of second integer
  
   add $t0,$t0,$t1
   add $t0,$t0,$t2 # Sums three integers

Solution

Solution:

#program that asks user for input three integers
#and prints its average

.data 0x10010000
      newline: .asciiz \"\ \"
      prompt:     .asciiz \"Enter 3 integers\ \"
     
      .globl main
     
     
.text
main:
      lui $v0, 0 #load instruction to print a string
      ori $v0, $0, 4
     
      lui $a0, 0x1001 #load address of string prompt
      ori $a0, $a0, 0x0002
      syscall
     
      lui $v0, 0 #load instruction to read 1st integer
      ori $v0, $0, 5
      syscall
      ori $t4,$v0,0
     
      lui $v0, 0 #load instruction to read 2nd integer
      ori $v0, $0, 5
      syscall
      ori $t5,$v0,0
     
      lui $v0, 0 #load instruction to read 3rd integer
      ori $v0, $0, 5
      syscall
      ori $t6,$v0,0
     
      add $t7,$t4,$t5
      add $t7,$t7,$t6
      ori $s0,$0,3
     
      div $t7,$s0
      mflo $t8
     
      lui $v0, 0 #load instruction to print a integer
      ori $v0, $0, 1
      ori $a0,$t8,0
      syscall
     
      lui $v0, 0 #load instruction to print a string
      ori $v0, $0, 4
     
      lui $a0, 0x1001 #load address of string to print newline
      ori $a0, $a0, 0x0000
      syscall
     
     
      mtc1 $t7,$f1
      mtc1 $s0,$f3
      div.s $f12, $f1, $f3
     
      lui $v0, 0 #load instruction to print a float
      ori $v0, $0, 2
      syscall
  

Write a MIPS program to solve the following problem: a. Prompt the user to enter 3 integer values. b. Read the integer. c. Calculate and print the average of th
Write a MIPS program to solve the following problem: a. Prompt the user to enter 3 integer values. b. Read the integer. c. Calculate and print the average of th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site