Question

Program the code using MARS simulator; Loops Write a program to calculate m n (m to...

Program the code using MARS simulator;

Loops

Write a program to calculate m n (m to the power of n).

Sample of input/output

Enter a value for m! 2

Enter a value for n! 3

2 to the power of 3 = 8

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

Given below is the code for the question. Please do rate the answer if it helped. Thank you.


.data
   msg1: .asciiz "Enter a value for m: "
   msg2: .asciiz "Enter a value for n: "
   outMsg: .asciiz " to the power of "
   equalto: .asciiz " = "
.text
  
   #print string
   li $v0, 4
   la $a0, msg1
   syscall
  
   #read int
   li $v0, 5
   syscall
   move $t0, $v0
  
  
   #print string
   li $v0, 4
   la $a0, msg2
   syscall
  
   #read int
   li $v0, 5
   syscall
   move $t1, $v0
  
   #perform repeated multiplication
   li $t2, 1 #result
   li $t3, 1 #counter
loop:
   bgt $t3, $t1, endloop
   mul $t2, $t2, $t0 #mulitply first number into current result
   add $t3, $t3, 1
   b loop

endloop:
   #display first number
   move $a0, $t0
   li $v0, 1
   syscall
  
   #print string
   li $v0, 4
   la $a0, outMsg
   syscall
  
   #display second number
   move $a0, $t1
   li $v0, 1
   syscall
  
   #print equal to symbol
   li $v0, 4
   la $a0, equalto
   syscall
  
   #display result
   move $a0, $t2
   li $v0, 1
   syscall
  
   #exit
   li $v0, 10
   syscall

output
-----
Enter a value for m: 2
Enter a value for n: 3
2 to the power of 3 = 8
-- program is finished running --

Enter a value for m: 3
Enter a value for n: 2
3 to the power of 2 = 9
-- program is finished running --

Add a comment
Know the answer?
Add Answer to:
Program the code using MARS simulator; Loops Write a program to calculate m n (m to...
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