Question

Write the codes as a text so I can copy them pls.

ALso, post a picture for testing by using MARS

Dont forget to coment each step pls

Write a complete MIPS-32 assembly language program including data declarations that uses a function Eval-Z, which evaluates the following expression Z = X-3(Y/ 8 + 125). Assume that caller program passes the values of X and Y to the function using registers Sa0 and Sal respectively while the result of executing the function is returned to the caller in register Sv0. The caller program should display the result on the console preceded by an appropriate message. Test your program using the following values (Xi, Yi) (100, 24) and (Xi, Yı)-(100, 21)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ScreenShot

-----------------------------------------------------------------------------------------------------------------------------------------------------------------

Code:-

#variable declaration
.data
   x: .asciiz "Enter the value of x : "
   y: .asciiz "Enter the value of Y : "
   z: .asciiz "The value of expression Z = X-3(Y/8+125) = "

#Main program
.text
#Enter the value of x variable
   la $a0,x                        #Ask the user to enter the value for x
   li $v0,4                        #print string
   syscall
   li $v0,5                        #read user enter value
   syscall
   move $t0,$v0                    #tore x value in to $t0

   #Enter the value of x variable
   la $a0,y                         #Ask the user to enter the value for y
   li $v0,4                         #print string
   syscall
   li $v0,5                         #read user enter value
   syscall
   move $a1,$v0                     #store y value in to $a1
   move $a0,$t0                     #store x value in to $a0

   jal Eval_Z                       #Function call to find expression value
   move $t0,$v0                     #return result from the function at $v0 store into $t0
   la $a0,z                         #Output message
   li $v0,4                         #read using system call
   syscall
   move $a0,$t0                      #move reult into $a0
   li $v0,1                          #display reult
   syscall
   li $v0, 10                        #end of the program
   syscall

   #function to evaluate expression
Eval_Z:subi $a0,$a0,3                #store value of x-3 in $a0     
       div $a1,$a1,8                 #store value of y/8 in $a1
       addi $a1,$a1,125              #store value of y/8+125 in $a1
       mul $v0,$a0,$a1               #store value of x-3(y/8+125) in $v0
       jr $ra                        #return to main program
   -----------------------------------------------------------------------------------------------------------------------------------------------

Output of (x1,y1)=(100,24)

Enter the value of x : 100
Enter the value of Y : 24
The value of expression Z = X-3(Y/8+125) = 12416
-- program is finished running --

Output of (x1,y1)=(100,21)

Enter the value of x : 100
Enter the value of Y : 21
The value of expression Z = X-3(Y/8+125) = 12319
-- program is finished running --

Add a comment
Know the answer?
Add Answer to:
Write the codes as a text so I can copy them pls. ALso, post a picture...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT