Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The folowing MIPS program drives the menu and calls subroutines. Subroutines handle specific tasks: compute _ series ( needs implementation ) : calculates a series
The folowing MIPS program drives the menu and calls subroutines. Subroutines handle specific tasks: computeseries needs implementation: calculates a series based on user input. dealwitharray: manages the user's array operations. addtoarray needs implementation: adds a value to the array. displayarray needs implementation: displays array elements or an empty message. The MIPS program: data msgwelcome: asciiz #Welcome to main menu msgchoice: asciiz "Enter to compute the series Enter to deal with array Enter to end the program msgsubchoice: asciiz Enter to add an element to the array Enter to display the array elements Enter to return to the main menu msgarrayempty: asciiz "Array is empty msgendseries: asciiz "Enter the end of series: msgentervalue: asciiz "Enter the value: msgsumis: asciiz "Sum is: # Array to store user entered values array: space # text section text main: # Print welcome message li $v la $a msgwelcome syscall loop: # Print menu choices li $v la $a msgchoice syscall # Read user choice li $v syscall add $t $v $zero # Option : Compute series beqz $t exit beq $t $one, computeseries # Option : Deal with array beq $t $two, dealwitharray j loop computeseries: # Print message to enter end of series li $v la $a msgendseries syscall # Read end of series value from user li $v syscall # Convert integer to float assuming user enters integer mtc $v $f # Call subroutine to compute series and store result in $f jal computeseriessub # Print message and result li $v la $a msgsumis syscall mfc $a $f li $v syscall j loop dealwitharray: # Print sub menu choices li $v la $a msgsubchoice syscall # Read user choice li $v syscall add $t $v $zero # Option : Add element to array beq $t $one, addtoarray # Option : Display array elements beq $t $two, displayarray # Option : Return to main menu beq $t $three, loop j dealwitharray # Handle invalid choice addtoarray: # Print message to enter value li $v la $a msgentervalue syscall # Read value from user li $v syscall # Convert integer to float assuming user enters integer mtc $v $f # Call subroutine to add element to array jal addtoarraysub # Print success message li $v la $a msgvalueadded syscall j dealwitharray displayarray: # Call subroutine to display array elements jal displayarraysub j dealwitharray exit: # Print exit message li $v la $a msgexit syscall li $v syscall # Subroutines computeseriessub: # Add your logic here to compute the series based on the value in $f and store the result in $f addtoarraysub: # Add your logic here to add the value in $f to the array displayarraysub: # Add your logic here to check if the array is empty and print a message if it is # If not empty, print the elements of the array Please fill in the subroutines such that it would resemble the sample output attached in this question.
The folowing MIPS program drives the menu and calls subroutines.
Subroutines handle specific tasks:
computeseries needs implementation: calculates a series based on user input.
dealwitharray: manages the user's array operations.
addtoarray needs implementation: adds a value to the array.
displayarray needs implementation: displays array elements or an empty message.
The MIPS program:
data
msgwelcome: asciiz
#Welcome to main menu
msgchoice: asciiz "Enter to compute the series
Enter to deal with array
Enter to end the program
msgsubchoice: asciiz
Enter to add an element to the array
Enter to display the array elements
Enter to return to the main menu
msgarrayempty: asciiz "Array is empty
msgendseries: asciiz "Enter the end of series:
msgentervalue: asciiz "Enter the value:
msgsumis: asciiz "Sum is:
# Array to store user entered values
array: space
# text section
text
main:
# Print welcome message
li $v
la $a msgwelcome
syscall
loop:
# Print menu choices
li $v
la $a msgchoice
syscall
# Read user choice
li $v
syscall
add $t $v $zero
# Option : Compute series
beqz $t exit
beq $t $one, computeseries
# Option : Deal with array
beq $t $two, dealwitharray
j loop
computeseries:
# Print message to enter end of series
li $v
la $a msgendseries
syscall
# Read end of series value from user
li $v
syscall
# Convert integer to float assuming user enters integer
mtc $v $f
# Call subroutine to compute series and store result in $f
jal computeseriessub
# Print message and result
li $v
la $a msgsumis
syscall
mfc $a $f
li $v
syscall
j loop
dealwitharray:
# Print sub menu choices
li $v
la $a msgsubchoice
syscall
# Read user choice
li $v
syscall
add $t $v $zero
# Option : Add element to array
beq $t $one, addtoarray
# Option : Display array elements
beq $t $two, displayarray
# Option : Return to main menu
beq $t $three, loop
j dealwitharray # Handle invalid choice
addtoarray:
# Print message to enter value
li $v
la $a msgentervalue
syscall
# Read value from user
li $v
syscall
# Convert integer to float assuming user enters integer
mtc $v $f
# Call subroutine to add element to array
jal addtoarraysub
# Print success message
li $v
la $a msgvalueadded
syscall
j dealwitharray
displayarray:
# Call subroutine to display array elements
jal displayarraysub
j dealwitharray
exit:
# Print exit message
li $v
la $a msgexit
syscall
li $v
syscall
# Subroutines
computeseriessub:
# Add your logic here to compute the series based on the value in $f and store the result in $f
addtoarraysub:
# Add your logic here to add the value in $f to the array
displayarraysub:
# Add your logic here to check if the array is empty and print a message if it is
# If not empty, print the elements of the array
Please fill in the subroutines such that it would resemble the sample output attached in this question.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored 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