Answered step by step
Verified Expert Solution
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 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
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
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started