Question

MARS MIP assembly language quesion Write a program that reads 3 integers, print them, stores them,...

MARS MIP assembly language quesion

Write a program that reads 3 integers, print them, stores them, and add them together and print the result

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

Answer:

.data
A: .word # Integer A
B: .word # Integer B
C: .word # Integer C
S: .word #Integer S use to store the sum of A and B
Prompt1: .asciiz "Please enter first number A: "
Prompt2: .asciiz "Please enter second number B: "
Prompt3: .asciiz "Please enter third number C: "
Result: .asciiz "The sum of A, B and C in S is : "
.text
main:
#Prompt for integers A
li $v0, 4 # Load instruction for printing the string
la $a0, Prompt1 # Load Prompt1 into $a0
syscall
#Read first integer
li $v0, 5 # Read first integer A
la $t0, A
syscall
#Store first integer A into the memory
move $t0, $v0
sw $t0, A   
  
##Prompt for integers B
li $v0, 4 # Load instruction for printing the string
la $a0, Prompt2 # Load prompt2 into $a0
syscall
#Read second integer
li $v0, 5 # Read second integer
la $t1, B # $t1 = B
syscall
#Store second integer into memory
move $t1, $v0 # Move contents in $v0 to $t0
sw $t1, B # B = value at $t1
  
##Prompt for integers C
li $v0, 4 # Load instruction for printing the string
la $a0, Prompt3 # Load prompt3 into $a0
syscall
#Read second integer
li $v0, 5 # Read second integer
la $t2, C # $t3 = C
syscall
#Store second integer into memory
move $t2, $v0 # Move contents in $v0 to $t2
sw $t2, C # C = value at $t2
  
#Add the three variables A, B and C and store it in S
la $t3, S # $t3 = S
add $t3, $t0, $t1 # $t3 = $t0 + $t1
add $t3, $t3, $t2 # $t3 = $t3 + $t2
sw $t3, S # S = value at $t3
#Display the Result prompt
la $a0, Result # Loads Output label to be printed
li $v0, 4 # Sysycall to print string
syscall
#Display the sum
lw $a0, S # $a0 = value at S
li $v0, 1 # Syscall to print integer
syscall
#Exit the program
li $v0, 10 # Load exit code to $v0
syscall

OUTPUT:
Please enter first number A: 3

Please enter second number B: 4

Please enter second number C: 2

The sum of A , B and C in S is : 9

Please give thumbsup, if you like it. Thanks.

Add a comment
Know the answer?
Add Answer to:
MARS MIP assembly language quesion Write a program that reads 3 integers, print them, stores them,...
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
ADVERTISEMENT