# Part1 - calculator .data #strings for retrieving information and returning result. prompt1: .asciiz "\nEnter first number\n" prompt2: .asciiz "Enter second number\n" operator: .asciiz "Enter operation\n" outmsg: .asciiz "\nThe result is:\n" .globl main .text main: # prompt for first number li \$v0, 4 la \$a0, prompt1 syscall # get number li \$v0, 5 syscall # move number to \$s0. \$v0 will be reused. add \$s0, \$zero, \$v0 # prompt for second number li \$v0, 4 la \$a0, prompt2 syscall li \$v0, 5 syscall # move 2nd number to \$s1 add \$s1, \$zero, \$v0 # prompt for operator li \$v0, 4 la \$a0, operator syscall # get operator li \$v0, 12 syscall # keep operator code in \$s2 add \$s2, \$zero, \$v0 # output message li \$v0, 4 la \$a0, outmsg syscall # Multi-if-then per expected operator li \$t0, '+' beq \$s2, \$t0, addt li \$t0, '-' beq \$s2, \$t0, subt li \$t0, '*' beq \$s2, \$t0, multi li \$t0, '/' beq \$s2, \$t0, divi # Wrong/unknown operation j exit addt: add \$t0, \$s0, \$s1 j print subt: sub \$t0, \$s0, \$s1 j print multi: mult \$s0, \$s1 mflo \$t0 # keep the low part of product j print divi: div \$s0, \$s1 mflo \$t0 #keep quotient j print print: li \$v0, 1 add \$a0, \$zero, \$t0 syscall exit: li \$v0, 10 syscall