In MARS MIPS Write a program to calculate the average of two

In MARS (MIPS)

Write a program to calculate the average of two values. Initialize the two values to be averaged in main. Pass these two values as parameters on the stack to the average procedure. Compute the average of the two value parameters. Use the stack to pass the result back to main.

Solution

.data prompt1: .asciiz \"\ \ Enter the first integer please:\" prompt2: .asciiz \"Enter the second integer please:\" result: .asciiz \"The result is:\" .text main: #t0-to hold first integer #t1-to hold second integer #t2- used to hold the average of t$1 and t$2 #first number li $v0, 4 #syscall to print string la $a0, prompt1 #address of string to print syscall # li $v0, 5 #syscall to read an integer syscall move $t0, $v0 #move the number to read into $t0 #second number li $v0, 4 la $a0, prompt2 syscall # li $v0,5 syscall move $t1,$v0 # #print out average of $t2 li $v0, 4 la $a0, result syscall # add $t2, $t1, $t0 #compute the sum sra $a, $t2, 1 #right shift by 1 place = divide by 2 li $v0, 1 syscall # li $v0, 10 syscall
In MARS (MIPS) Write a program to calculate the average of two values. Initialize the two values to be averaged in main. Pass these two values as parameters on

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site