Question: 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
prompt: asciiz "Please enter the first integer:
prompt: asciiz "Please enter the second integer:
prompt: asciiz "Please enter a math function among or :
outputadd: asciiz "Integer Integer
outputsub: asciiz "Integer Integer
outputmul: asciiz "Integer Integer
outputdiv: asciiz "Integer Integer
errormsg: asciiz "Invalid function! Please enter or :
text
main:
# Prompt for and read the first integer
li $v
la $a prompt
syscall # prompt for the first integer
li $v
syscall
move $s $v # move the first integer to $s
# Prompt for and read the second integer
li $v
la $a prompt # load address of prompt
syscall # prompt for the second integer
li $v
syscall
move $s $v # move the second integer to $s
# Prompt for and read the math function
li $v
la $a prompt # load address of prompt
syscall # prompt for the math function
li $v
syscall
move $t $v # move the character to $t
# Branch based on the selected function
beq $t performadd
beq $t performsub
beq $t performmul
beq $t performdiv
# Invalid function error message
li $v
la $a errormsg # load address of errormsg
syscall # print error message
j exit # exit the program
performadd:
add $t $s $s # Integer Integer
li $v
la $a outputadd
syscall
move $a $t
li $v
syscall
j exit
performsub:
sub $t $s $s # Integer Integer
li $v
la $a outputsub
syscall
move $a $t
li $v
syscall
j exit
performmul:
mult $s $s # Integer Integer
mflo $t
li $v
la $a outputmul
syscall
move $a $t
li $v
syscall
j exit
performdiv:
div $s $s # Integer Integer
mflo $t
li $v
la $a outputdiv
syscall
move $a $t
li $v
syscall
j exit
exit:
# Exit the program
li $v # syscall for exit
syscall
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
