Question

Create a program that, given two inputs a and b, will output the following: • (a*b+b*3)...

Create a program that, given two inputs a and b, will output the following: • (a*b+b*3) Create a function that will perform this calculation, and use $a0 and $a1 as the argument registers, and $v0 for the return value. Ensure that you are able to call this function with additional statements before and after the call: for example, you may be asked to place an addi a, a, 3 call before the function is called, or to calculate the return of the function multiplied by 3, etc. This code is written in MIPs and has to do with functions I can't quite figure it out. it has been answered before but that code is incorrect.

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

Please find the code below::

.data
a : .word 2
b : .word 3


.text
main :
  
#setting parameter for function
lw $a0,a
lw $a1,b
jal calculataValue #call function
  
move $t1,$v0 #copy value from v0
li $v0,1
move $a0,$t1 #print a value
syscall
     
li $v0,10 #stop execution
syscall
  
calculataValue : #function definition
    mul $t0,$a0,$a1 #calculate a*b
    mul $t1,$a1,3 #calculate b*3
    add $v0,$t0,$t1 #calculate a*b + b*3   
  
jr $ra #return value

output:

Add a comment
Know the answer?
Add Answer to:
Create a program that, given two inputs a and b, will output the following: • (a*b+b*3)...
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