Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write and debug a MIPS program that performs the following operations: Prompt fo

ID: 3910391 • Letter: W

Question

Write and debug a MIPS program that performs the following operations:

Prompt for and input three integers “a”, “b”, “c” using syscalls

Display one of the following statements depending on if a+b>c, or a+b=c or a+b<c:

- You entered a+b greater than c

- You entered a+b equal to c

- You entered a+b less than c

Compute
1. 7*(a+b)+c

2. (c-2)*(a+b)+1

3. (a+b)*(c-2)*(b+5)
and display the result of each computation. Be careful with operator precedence. Return to the operating system.

Your run’s output must look exactly in format like the sample below. (If only close, but not exact, will result in lost points.). Note that only the output result will vary depending on the input numbers. Adjust your code until your output exactly matches (including horizontal and vertical spacing). You can use " to put a double quote inside a text string. The values shown in bold here (not in your console window) are user inputs for this run.

What is integer "a"? 3

What is integer "b"? 4

What is integer "c"? 20

1. You will need to use .text and .data directives to define program and data areas in SPIM.

2. A colon (:) must follow all labels. Note that labels allow easy reference to a specific address/place in the program or

an argument that is required.

3. Each data entry must be uniquely labeled to avoid any potential error.

4. The word "main:" must label the first line in a SPIM program and always be made global.

5. You may write only one instruction to a line (once past the instruction, you may add a comment, simply preceding with

a # sign).

6. All characters in a string are represented in ASCII code.

7. Use comments (#) to adequately write the logic of the program. Note comments do not wrap. If a comment takes

more than one line, start a new line with # and continue your comment.

8. A "syscall 10" to return control to OS. For example, li $v0, 10

syscall

9. For better readability well format your code:

use distinct columns for labels, opcode, operands and comments

Explanation / Answer

ScreenShot

------------------------------------------------------------------------

Code

#Variable declaration
.data
     Prompt: .asciiz "What is integer "
     varA: .asciiz "a"
     qMark: .asciiz "?"
     varB: .asciiz "b"
     varC: .asciiz "c"
     equal: .asciiz "You entered a+b equal to c "
     greater: .asciiz "You entered a+b greater than c "
     lesser: .asciiz "You entered a+b less than c "
     firstEq: .asciiz "7*(a+b)+c is "
     secondEq: .asciiz "(c-2)*(a+b)+1 is "
     thirdEq: .asciiz "(a+b)*(c-2)*(b+5) is "
     nextLine: .asciiz " "
#main function
.text
.globl main
main:
     #Prompt for a
     la $a0,Prompt
     li $v0,4
     syscall
     #for "
     li $a0,34
     li $v0,11
     syscall
     #for variable a
     la $a0,varA
     li $v0,4
     syscall
     #for "
     li $a0,34
     li $v0,11
     syscall
     #for ?
     la $a0,qMark
     li $v0,4
     syscall
     #read user input
     li $v0,5
     syscall
     #store a value in t0
     move $t0,$v0
   
     #Prompt for b
     la $a0,Prompt
     li $v0,4
     syscall
     #for "
     li $a0,34
     li $v0,11
     syscall
     #for variable b
     la $a0,varB
     li $v0,4
     syscall
     #for "
     li $a0,34
     li $v0,11
     syscall
     #for ?
     la $a0,qMark
     li $v0,4
     syscall
     #read user input
     li $v0,5
     syscall
     #store a value in t1
     move $t1,$v0
   
    #Prompt for c
     la $a0,Prompt
     li $v0,4
     syscall
     #to display symbol "
     li $a0,34
     li $v0,11
     syscall
     #for variable c
     la $a0,varC
     li $v0,4
     syscall
     #for "
     li $a0,34
     li $v0,11
     syscall
     #t0 display ?
     la $a0,qMark
     li $v0,4
     syscall
     #read user input
     li $v0,5
     syscall
     #store a value in t2
     move $t2,$v0
   
     #find a+b
     add $s0,$t0,$t1
     #compare
     beq $s0,$t2,equalTest
     blt $s0,$t2,lessTest
     bgt $s0,$t2,greatTest
#If a+b=c then display equal message
equalTest:
     la $a0,equal
     li $v0,4
     syscall
     j Equation
#If a+b<c then display lesser message
lessTest:
     la $a0,lesser
     li $v0,4
     syscall
     j Equation
#If a+b>c then display greater message
greatTest:
     la $a0,greater
     li $v0,4
     syscall
     j Equation
#Equations solving
Equation:
     #firstEquation
     la $a0,firstEq   #display equation
     li $v0,4
     syscall
     li $t3,7        #t3=7
     mul $a0,$t3,$s0 #a0=7*(a+b)
     add $a0,$a0,$t2 #a0=7*(a+b)+c
     #display result
     li $v0,1
     syscall
     #go to next line
     la $a0,nextLine
     li $v0,4
     syscall
   
     #secondEquation
     la $a0,secondEq #display equation
     li $v0,4
     syscall
     li $s1,2          #s1=2
     sub $s1,$t2,$s1   #s1=(c-2)
     mul $a0,$s1,$s0   #(c-2)*(a+b)
     li $t3,1          #t3=1
     add $a0,$a0,$t3   #(c-2)*(a+b)+1
     #Display result
     li $v0,1
     syscall
     #go to next line
     la $a0,nextLine
     li $v0,4
     syscall
   
     #thirdEquation
     la $a0,thirdEq    #display equation
     li $v0,4
     syscall
     li $t3,5          #t3=5
     add $t3,$t1,$t3   #t3=b+5
     mul $a0,$s0,$s1   #a0=(a+b)*(c-2)
     mul $a0,$a0,$t3   #a0=(a+b)*(c-2)*(b+5)
     #Display result
     li $v0,1
     syscall
     #end of the program
     li $v0,10
     syscall

-------------------------------------------------------------

Output

What is integer "a"?3
What is integer "b"?4
What is integer "c"?20
You entered a+b less than c
7*(a+b)+c is 69
(c-2)*(a+b)+1 is 127
(a+b)*(c-2)*(b+5) is 1134
-- program is finished running --

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote