Question

MIPS -

Takes two inputs from the user, which are the lengths of two sides of a polygon. It adds those two lengths and prints the sum. Your task is modify the program to make it specific to a triangle, and to print the perimeter of that triangle.

See blue highlighted.

preamble: prompt1: prompt2: answer: endline: .data ascii .asciiz asciiz .asciiz asciiz .asciiz \nThis program, written by <Y

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

PROGRAM:

.data
   preamble: .ascii "\nThis program, written by PALLAVI, "
       .asciiz "can be used to add three sides of a triangle(i.e., Preimeter of a triangle).\n"
   prompt1: .asciiz "Enter the length of first side: "
   prompt2: .asciiz "Enter the length of second side: "
   prompt3: .asciiz "Enter the length of third side: "
   answer: .asciiz "Perimeter of triangle is: "
.text
.globl main
main:
   li $v0,4       # 4 is the print_string syscall
   la $a0,preamble       # Load the address of preamble into $a0
   syscall           # Printhe the preamble
  
   li $v0,4       # 4 is the print_string syscall
   la $a0,prompt1       # Load the address of prompt1 into $a0
   syscall           # Print the prompt
   li $v0,5       # 5 is the read integer syscall
   syscall           # read the integer which gets stored in $v0
   move $t0,$v0       # put the read integer in $t0 for further processing
  
   li $v0,4       # 4 is the print_string syscall
   la $a0,prompt2       # Load the address of prompt2 into $a0
   syscall           # Print the prompt
   li $v0,5       # 5 is the read integer syscall
   syscall           # read the integer which gets stored in $v0
   move $t1,$v0       # put the read integer in $t1 for further processing
  
   li $v0,4       # 4 is the print_string syscall
   la $a0,prompt3       # Load the address of prompt3 into $a0
   syscall           # Print the prompt
   li $v0,5       # 5 is the read integer syscall
   syscall           # read the integer which gets stored in $v0
   move $t2,$v0       # put the read integer in $t2 for further processing
  
   add $t3,$t0,$t1       # $t3 = a+b i.e., sum of first 2 sides
   add $t3,$t3,$t2       # $t3 = $t3+c i.e., Adding third side to above result
  
   li $v0,4       # 4 is the print_string syscall
   la $a0,answer       # Load the address of answer into $a0
   syscall           # Print the answer string
   li $v0,1       # 1 is the print integer syscall
   move $a0,$t3       # Put the value from $t3 in $a0 for printing
   syscall           # Print the answer number
  
   li $v0,10       # 10 is the exit program syscall
   syscall           # Exit the program

Please refer to the following screenshot of the program for indentation of the code:

Hemo . data preamble: .ascii nThis program, written by PALLAVI, .asciiz can be used to add three sides of a triangle(i.e.

OUTPUT:

Mars Messages Run I/O This program, written by PALLAVI, can be used to add three sides of a triangle(i.e., Preimeter of a tri

Add a comment
Know the answer?
Add Answer to:
MIPS - Takes two inputs from the user, which are the lengths of two sides of...
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