Answered step by step
Verified Expert Solution
Link Copied!

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:
compute_series (needs implementation): calculates a series based on user input.
deal_with_array: manages the user's array operations.
add_to_array (needs implementation): adds a value to the array.
display_array (needs implementation): displays array elements or an empty message.
The MIPS program:
.data
msg_welcome: .asciiz "
#Welcome to main menu
"
msg_choice: .asciiz "Enter 1 to compute the series
Enter 2 to deal with array
Enter 0 to end the program
"
msg_sub_choice: .asciiz "
Enter 1 to add an element to the array
Enter 2 to display the array elements
Enter 3 to return to the main menu
"
msg_array_empty: .asciiz "Array is empty
"
msg_end_series: .asciiz "Enter the end of series: "
msg_enter_value: .asciiz "Enter the value: "
msg_sum_is: .asciiz "Sum is: "
# Array to store user entered values
array: .space 40
# .text section
.text
main:
# Print welcome message
li $v0,4
la $a0, msg_welcome
syscall
loop:
# Print menu choices
li $v0,4
la $a0, msg_choice
syscall
# Read user choice
li $v0,5
syscall
add $t0, $v0, $zero
# Option 1: Compute series
beqz $t0, exit
beq $t0, $one, compute_series
# Option 2: Deal with array
beq $t0, $two, deal_with_array
j loop
compute_series:
# Print message to enter end of series
li $v0,4
la $a0, msg_end_series
syscall
# Read end of series value from user
li $v0,6
syscall
# Convert integer to float (assuming user enters integer)
mtc1 $v0, $f12
# Call subroutine to compute series and store result in $f0
jal compute_series_sub
# Print message and result
li $v0,4
la $a0, msg_sum_is
syscall
mfc1 $a0, $f0
li $v0,2
syscall
j loop
deal_with_array:
# Print sub menu choices
li $v0,4
la $a0, msg_sub_choice
syscall
# Read user choice
li $v0,5
syscall
add $t0, $v0, $zero
# Option 1: Add element to array
beq $t0, $one, add_to_array
# Option 2: Display array elements
beq $t0, $two, display_array
# Option 3: Return to main menu
beq $t0, $three, loop
j deal_with_array # Handle invalid choice
add_to_array:
# Print message to enter value
li $v0,4
la $a0, msg_enter_value
syscall
# Read value from user
li $v0,6
syscall
# Convert integer to float (assuming user enters integer)
mtc1 $v0, $f12
# Call subroutine to add element to array
jal add_to_array_sub
# Print success message
li $v0,4
la $a0, msg_value_added
syscall
j deal_with_array
display_array:
# Call subroutine to display array elements
jal display_array_sub
j deal_with_array
exit:
# Print exit message
li $v0,4
la $a0, msg_exit
syscall
li $v0,10
syscall
# Subroutines
compute_series_sub:
# Add your logic here to compute the series based on the value in $f12 and store the result in $f0
add_to_array_sub:
# Add your logic here to add the value in $f12 to the array
display_array_sub:
# 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.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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