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
  • WRITE THE FOLLOWING CODE IN FLOATING POINT NUMBERS IN ASSEMBLY LANGUAGE USING MIPS IN MARS .data...

    WRITE THE FOLLOWING CODE IN FLOATING POINT NUMBERS IN ASSEMBLY LANGUAGE USING MIPS IN MARS .data prompt: .asciiz "\nMaximum number is : " prompt1: .asciiz "\nMinimum number is : " prompt2: .asciiz "\nRange of the array is : " size: .word 10 #load array array: .word 23, -12, 45, -32, 52, -72, 8, 13,22,876 .text #load address of array and size la $s4,array #load address of A lw $t0,size #load i to t0 jal getArrayRange li $v0, 4    la...

  • Subroutines in MIPS Determines the minimum of two integers Functions within the MIPS slides describe how...

    Subroutines in MIPS Determines the minimum of two integers Functions within the MIPS slides describe how one can use subroutines (also called procedures, functions, and methods) in MIPS. Because of the importance of subroutines in modern programming, most hardware designers include mechanisms to help programmers. In a high-level language like C or Java, most of the details of subroutine calling are hidden from the programmer. MIPS has special registers to send information to and from a subroutine. The registers $a0,...

  • In the SPIM simulator in MIPS assembly, write the itri routine in the itri.s skeleton to...

    In the SPIM simulator in MIPS assembly, write the itri routine in the itri.s skeleton to make it print an inverted triangle. The height of the triangle will be given in $a0, and will be between 1 and 40 inclusive. For the first three tests, the included test harness should print (spimsimulator(dot)sourceforge(dot)net) 1. (25 pts.) In the SPIM simulator in MIPS assembly, write the itri routine in the itri.s skeleton to make it print an inverted trian- gle. The height...

  • Hello, I'm having trouble completing this program in less than four lines using MIPS programming language,...

    Hello, I'm having trouble completing this program in less than four lines using MIPS programming language, we are required to fill in the missing code as indicated (via comments). IMPORTANT: As indicated in the program's comments: ⇒ Write no more than certain number of lines of code as indicated. (One instruction per line, and there will be penalty if your code consumes more lines.) ⇒ Code MUST use only instructions that are allowed i.e., only bit manipulating instructions: (ANDing, ORing,...

  • Refer the program in the next page: Assume the starting address of data segment: 0x10010000. What...

    Refer the program in the next page: Assume the starting address of data segment: 0x10010000. What is the address of label num3? _______________________________ Write the common syscall code to print string for the blank marked as #Question 2 _________________________________ Write proper comments for the lines marked as #Question 3 ________________________________________________________ Write the machine code for the line marked as #Question 4 in both binary and hex. Binary:_______________________________________ Hex:___________________ Write the machine code for the line marked as #Question 5 in...

  • .data prompt: .asciiz "Input an integer x:\n" result: .asciiz "Fact(x) = " .text main: # show prompt li $v0, 4 la $a0, prompt syscall # read x li $v0, 5 syscall # function call move $a...

    .data prompt: .asciiz "Input an integer x:\n" result: .asciiz "Fact(x) = " .text main: # show prompt li $v0, 4 la $a0, prompt syscall # read x li $v0, 5 syscall # function call move $a0, $v0 jal factorial # jump factorial and save position to $ra move $t0, $v0 # $t0 = $v0 # show prompt li $v0, 4 la $a0, result syscall # print the result li $v0, 1 # system call #1 - print int move $a0,...

  • Assignment 4 File “quad_sol.s” contains a quadratic polynomial solver, which calculates the integer solution of a quadratic polynomial equation. 1. Rewrite the program using instructions reordering to...

    Assignment 4 File “quad_sol.s” contains a quadratic polynomial solver, which calculates the integer solution of a quadratic polynomial equation. 1. Rewrite the program using instructions reordering to reduce the number of cycles needed to execute the program. Indicate the number of cycle reduction. 2. Describe how forwarding would affect the execution of the program. CODE # quad_sol.s # This assembly program calculates the integer solutions of a quadratic polynomial. # Inputs : The coefficients a,b,c of the equation a*x^2 +...

  • 1. Modify larger.s to let the user to enter three numbers and output the largest value...

    1. Modify larger.s to let the user to enter three numbers and output the largest value # larger.s-- prints the larger of two numbers specified # at runtime by the user. # Registers used: # $t0 - used to hold the first number. # $t1 - used to hold the second number. # $t2 - used to store the larger of $t1 and $t2. # $v0 - syscall parameter and return value. # $a0 - syscall parameter. .text main: ##...

  • MIPS Insertion program.........I could really use some help ASAP

    I have this MIPS program and I'm having trouble with it. This program is user inputs numbers until zero and sorts and print the numbers in order. Please soove this issue. You can use any sorting algorithm except bubble sort.  Need it as soon as possible. Here is the code:.datanum: .word 0space: .byte ' ' .text main:  # la $t0, val # loads val into a register  # li $t1, 0      #keeps track of how many numbers entered  la $a0,...

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