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

Write a desktop calculator in MIPS and test it on MARS. On startup, the calculat

ID: 670323 • Letter: W

Question

Write a desktop calculator in MIPS and test it on MARS. On startup, the calculator should accept input strings. The following are legal input strings. After every input string is received, the result of math should be printed. Assume that only positive integers are provided as input operands (referred to as op1 and op2). but the result of an operation may be negative. Note that the operands are provided as part of the input string and have to be converted into integers. Assume that all math is confined to 32 bits and there are no overflows or divide by zeros, Input "e": quit the program Input "+ op1 op2": add op1 and op2 Input "+ op1": add op1 to the result of the previous operation o Input "-op1 op2": perform op1 - op2 Input "-op1": subtract op1 from the result of the previous operation o Input "*op1": multiply op1 to the result of the previous operation Input "/op1": divide the result of the previous operation by op1 o Input "% op1": the remainder after dividing the result of the previous operation by op1 An example set of operations in one run of the program: + 5 7 12 + 3 15 - 14 8 6 - 2 4 *5 20 / 2 10 % 3 1 e

Explanation / Answer


lw $t0, 5
lw $t1, 7
add $t2,$t0,$t1

lw $t0,3
lw $t1,$t2
add $t2,$t1,$t0

lw $t0,14
lw $t1,8
sub $t2,$t0,$t1

lw $t0, 2
sub $t3,$t2,t0

lw $t0,5
mult $t3,$t0

lw $t2,$LO
lw $t0,2
div $t2,$t0

lw t0, 3
lw $t1,$LO
div $t1,$t0

lw $t0,$HI # 1 final result

li $v0,10
syscall #call operating sys

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