Question

In: Computer Science

Write a simple MIPS Assembly program to average 3 integers. Make sure to read in three...

Write a simple MIPS Assembly program to average 3 integers. Make sure to read in three numbers from the user instead of hard coding them. To divide the sum by 3 you may use div $t0, $t0, 3 where register $t0 conatins the sum of the 3 integers.

.data
prompt1: .asciiz " Please enter an integer: "
prompt2: .asciiz " Please enter an integer: "
prompt3: .asciiz " Please enter an integer: "
result: .asciiz "The average of three number is: "

       .text

main:

  
   li $v0, 4 # syscall to print string
   la $a0, prompt1
   syscall

   li $v0, 5 # syscall to read an integer
   syscall
   move $t0, $v0 # move number to read into $t0

   li $v0, 4
   la $a0, prompt2
   syscall

   li $v0,5
   syscall
   move $t1, $v0

   li $v0, 4
   la $a0, prompt3
   syscall

   li $v0,5
   syscall
   move $t2, $v0

   # add all integers to $t3
   add $t3, $t0, $t1
   add $t3, $t2, $t3
   li $v0, 1
   syscall

   # Read the sum
   li $v0, 3
   syscall
   move $t3, $v0

   # Divide Sum / count
   div $t4, $t3, 3
   #li $v0, 1
   #move $a0, $t4


   #print out the average
   move $a0, t4
   li $v0, 1
   la $a0, result
   syscall

   exit:
   li $v0, 10
   syscall

Whats the problem?

Solutions

Expert Solution

Greetings!!

Code:

#DATA SEGMENT

.data

prompt1: .asciiz " Please enter an integer: "

prompt2: .asciiz " Please enter an integer: "

prompt3: .asciiz " Please enter an integer: "

result: .asciiz "The average of three number is: "

#CODE SEGMENT

.text

main:

   #DISPLAY PROMPT1

   li $v0, 4                    #parameter to print string

   la $a0, prompt1        #address of prompt1

   syscall                      #syscall for print string

  

   #READ 1ST NUMBER

   li $v0, 5                    #parameter to read an integer

   syscall                      #syscall for read number

   move $t0, $v0          #move number read to register $t0

  

   #DISPLAY PROMPT2

   li $v0, 4                    #parameter to print string

   la $a0, prompt2        #address of prompt2

   syscall                      #syscall for print string

  

   #READ 2ND NUMBER

   li $v0,5                     #parameter to read an integer

   syscall                      #syscall for read number

   move $t1, $v0          #move number read to register $t1

  

   #DISPLAY PROMPT3

   li $v0, 4                    #parameter to print string

   la $a0, prompt3        #address of prompt2

   syscall                      #syscall for print string

  

   #READ 3RD NUMBER

   li $v0,5                     #parameter to read an integer

   syscall                      #syscall for read number

   move $t2, $v0          #move number read to register $t2

  

   # ADD ALL INTEGERS TO $T3

   add $t3, $t0, $t1       #sum of first 2 numbers into t3

   add $t3, $t2, $t3       #sum of 3 numbers into t3

  

   # DIVIDE SUM / COUNT

   div $t4, $t3, 3           #calculate the average

  

   #DISPLAY MESSAGE "THE AVERAGE OF..."

   li $v0, 4                    #parameter for display string

   la $a0, result             #address of the string

   syscall                      #system call for display string

  

   #PRINT OUT THE AVERAGE

   move $a0,$t4           #load the average into register a0 for display

   li $v0, 1                    #parameter for display number

   syscall                      #system call for display number

  

   #TERMINATE THE EXECUTION  

   li $v0, 10

   syscall

Output screenshot:

Hope this helps


Related Solutions

IN MIPS ASSEMBLY LANGUAGE Write an assembly program to read three 32-bit signed integers from the...
IN MIPS ASSEMBLY LANGUAGE Write an assembly program to read three 32-bit signed integers from the user. Determine the smallest of these three numbers and display this result. Don’t use loops. Prompt the user for each entered integer. Your output should look something like the following example. Enter an integer: 7556 Enter an integer: -22984 Enter an integer: 8875 -22984
Write a MIPS Assembly Language program to perform the following operations: Request and read two integers...
Write a MIPS Assembly Language program to perform the following operations: Request and read two integers from the console (Dn and Up), Call a recursive function to compute the result int RecurseFunc( int Dn, int Up ) { if( Dn < 1 ) return 0; return Dn * Up + RecurseFunc( Dn - 1, Up + 1 ); } Print out the results
Write a MIPS Assembly Language program to perform the following operations: Request and read two integers...
Write a MIPS Assembly Language program to perform the following operations: Request and read two integers from the console (Dn and Up), Call a recursive function to compute the result int RecurseFunc( int Dn, int Up ) { if( Dn < 1 ) return 0; else return Dn * Up + RecurseFunc( Dn - 1, Up + 1 ); } Print out the results Submit your code and report here.
Write a MIPS Assembly Language program to perform the following operations: Request and read two integers...
Write a MIPS Assembly Language program to perform the following operations: Request and read two integers from the console (Dn and Up), Call a recursive function to compute the result int RecurseFunc( int Dn, int Up ) { if( Dn < 1 ) return 0; return Dn * Up + RecurseFunc( Dn - 1, Up + 1 ); } Print out the results
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product and quotient without using the multiplication and division instructions. Each input number will be entered on a separate line. Your program will terminate when two zeroes are entered by the user. If only the second number in a pair is zero, then a divide-by-zero error message should be printed for the division operation. Use comments generously in your program. Test your program with the...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product and quotient without using the multiplication and division instructions. Each input number will be entered on a separate line. Your program will terminate when two zeroes are entered by the user. If only the second number in a pair is zero, then a divide-by-zero error message should be printed for the division operation. Use comments generously in your program. Test your program with the...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product and quotient without using the multiplication and division instructions. Each input number will be entered on a separate line. Your program will terminate when two zeroes are entered by the user. If only the second number in a pair is zero, then a divide-by-zero error message should be printed for the division operation. Use comments generously in your program. Test your program with the...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product and quotient without using the multiplication and division instructions. Each input number will be entered on a separate line. Your program will terminate when two zeroes are entered by the user. If only the second number in a pair is zero, then a divide-by-zero error message should be printed for the division operation. Use comments generously in your program. Test your program with the...
Write an assembly code in MIPS program that can read 3 numbers from the user and...
Write an assembly code in MIPS program that can read 3 numbers from the user and print the following: a. The summation b. The average c. The minimum d. The maximum e. Print the values between the minimum and maximum f. Write comments to explain each line in your code -look at Fibonacci code- (no comments mean zero for the assignment ) use MARS MIPS .
Write a mips assembly language program to ask the user to enter two integers A and...
Write a mips assembly language program to ask the user to enter two integers A and B and then display the result of computing the expression: A + 2B - 5.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT