Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please modify my MIPS program such that my compute _ series subroutine will deal with floating numbers instead of an integer. Example of what i
Please modify my MIPS program such that my computeseries subroutine will deal with floating numbers instead of an integer. Example of what i want my subroutine to compute is shown in the image that i sent.
My MIPS Program:
data
array: space # Reserve space for the array
arraysize: word # Variable to track the size of the array
messageempty: asciiz "Array is empty"
messageprompt: asciiz "Enter the end of the series:
messagemenu: asciiz "Main Menu
Compute a series of numbers
Deal with array
Exit
Enter your choice:
messagesubmenu: asciiz "Array Menu
Add number to array
Print array
Back to main menu
Enter your choice:
text
globl main
main:
# Initialize arraysize to
li $t
sw $t arraysize
mainmenu:
# Display the main menu and get user input
li $v
la $a messagemenu
syscall
# Read user choice
li $v
syscall
move $t $v # Store user choice
# Handle user choice
beq $t exitprogram
beq $t computeseries
beq $t arraymenu
j mainmenu # Return to main menu if invalid choice
computeseries:
# Prompt user for series end
li $v
la $a messageprompt
syscall
# Read series end from user
li $v
syscall
move $t $v # Store series end
# Compute series: n
li $t # Initialize sum to
li $t # Initialize loop counter to
computeloop:
bgt $t $t computedone # Exit loop if counter series end
# Calculate n
move $t $t # Store counter value in $t
li $t # Numerator is always
div $t $t # Divide by counter
add $t $t $t # Add result to sum
addi $t $t # Increment counter
j computeloop
computedone:
# Display the sum
li $v
move $a $t
syscall
j mainmenu # Return to main menu
arraymenu:
# Display array menu and get user input
li $v
la $a messagesubmenu
syscall
# Read user choice
li $v
syscall
move $t $v # Store user choice
# Handle user choice
beq $t addtoarray
beq $t printarray
beq $t mainmenu
j arraymenu # Return to array menu if invalid choice
addtoarray:
# Prompt user to enter a number
li $v
la $a messageprompt
syscall
# Read user input number
li $v
syscall
move $t $v # Store user input
# Store number in the array
lw $t arraysize # Load current size of array
sw $t array$t # Store number in array at index size
addi $t $t # Increment array size
sw $t arraysize # Update array size
j arraymenu # Return to array menu
printarray:
# Check if array is empty
lw $t arraysize # Load current size of array
beqz $t printempty # If size is array is empty
# Print array elements
li $t # Initialize loop counter to
printloop:
bge $t $t arrayprinted # Exit loop if counter array size
# Load array element and print
lw $a array$t
li $v
syscall
addi $t $t # Increment counter
j printloop
arrayprinted:
j arraymenu # Return to array menu
printempty:
# Print "Array is empty"
li $v
la $a messageempty
syscall
j arraymenu # Return to array menu
exitprogram:
# Exit program
li $v
syscall
Please show full code.
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