Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Coding help. PLease revise the code below. . data prompt 1 : . asciiz Please enter the first integer: prompt 2 : . asciiz

Coding help. PLease revise the code below.
.data
prompt1: .asciiz "Please enter the first integer: "
prompt2: .asciiz "Please enter the second integer: "
prompt3: .asciiz "Please enter a math function among +,-,*, or /: "
output_add: .asciiz "Integer 1+ Integer 2="
output_sub: .asciiz "Integer 1- Integer 2="
output_mul: .asciiz "Integer 1* Integer 2="
output_div: .asciiz "Integer 1/ Integer 2="
error_msg: .asciiz "Invalid function! Please enter +,-,*, or /: "
.text
main:
# Prompt for and read the first integer
li $v0,4
la $a0, prompt1
syscall # prompt for the first integer
li $v0,5
syscall
move $s0, $v0 # move the first integer to $s0
# Prompt for and read the second integer
li $v0,4
la $a0, prompt2 # load address of prompt2
syscall # prompt for the second integer
li $v0,5
syscall
move $s1, $v0 # move the second integer to $s1
# Prompt for and read the math function
li $v0,4
la $a0, prompt3 # load address of prompt3
syscall # prompt for the math function
li $v0,12
syscall
move $t0, $v0 # move the character to $t0
# Branch based on the selected function
beq $t0,'+', perform_add
beq $t0,'-', perform_sub
beq $t0,'*', perform_mul
beq $t0,'/', perform_div
# Invalid function error message
li $v0,4
la $a0, error_msg # load address of error_msg
syscall # print error message
j exit # exit the program
perform_add:
add $t1, $s0, $s1 # Integer 1+ Integer 2
li $v0,4
la $a0, output_add
syscall
move $a0, $t1
li $v0,1
syscall
j exit
perform_sub:
sub $t1, $s0, $s1 # Integer 1- Integer 2
li $v0,4
la $a0, output_sub
syscall
move $a0, $t1
li $v0,1
syscall
j exit
perform_mul:
mult $s0, $s1 # Integer 1* Integer 2
mflo $t1
li $v0,4
la $a0, output_mul
syscall
move $a0, $t1
li $v0,1
syscall
j exit
perform_div:
div $s0, $s1 # Integer 1/ Integer 2
mflo $t1
li $v0,4
la $a0, output_div
syscall
move $a0, $t1
li $v0,1
syscall
j exit
exit:
# Exit the program
li $v0,10 # syscall for exit
syscall
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions