Answered step by step
Verified Expert Solution
Link Copied!

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 compute_series 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. (S=12+13+14+...1n)
My MIPS Program:
.data
array: .space 1000 # Reserve space for the array
array_size: .word 0 # Variable to track the size of the array
message_empty: .asciiz "Array is empty"
message_prompt: .asciiz "Enter the end of the series: "
message_menu: .asciiz "Main Menu
1. Compute a series of numbers
2. Deal with array
0. Exit
Enter your choice: "
message_submenu: .asciiz "Array Menu
1. Add number to array
2. Print array
3. Back to main menu
Enter your choice: "
.text
.globl main
main:
# Initialize array_size to 0
li $t0,0
sw $t0, array_size
main_menu:
# Display the main menu and get user input
li $v0,4
la $a0, message_menu
syscall
# Read user choice
li $v0,5
syscall
move $t1, $v0 # Store user choice
# Handle user choice
beq $t1,0, exit_program
beq $t1,1, compute_series
beq $t1,2, array_menu
j main_menu # Return to main menu if invalid choice
compute_series:
# Prompt user for series end
li $v0,4
la $a0, message_prompt
syscall
# Read series end from user
li $v0,5
syscall
move $t2, $v0 # Store series end
# Compute series: 1/1+1/2+...+1/n
li $t0,0 # Initialize sum to 0
li $t3,1 # Initialize loop counter to 1
compute_loop:
bgt $t3, $t2, compute_done # Exit loop if counter > series end
# Calculate 1/n
move $t4, $t3 # Store counter value in $t4
li $t5,1 # Numerator is always 1
div $t5, $t4 # Divide 1 by counter
add $t0, $t0, $t2 # Add result to sum
addi $t3, $t3,1 # Increment counter
j compute_loop
compute_done:
# Display the sum
li $v0,1
move $a0, $t0
syscall
j main_menu # Return to main menu
array_menu:
# Display array menu and get user input
li $v0,4
la $a0, message_submenu
syscall
# Read user choice
li $v0,5
syscall
move $t1, $v0 # Store user choice
# Handle user choice
beq $t1,1, add_to_array
beq $t1,2, print_array
beq $t1,3, main_menu
j array_menu # Return to array menu if invalid choice
add_to_array:
# Prompt user to enter a number
li $v0,4
la $a0, message_prompt
syscall
# Read user input (number)
li $v0,5
syscall
move $t2, $v0 # Store user input
# Store number in the array
lw $t3, array_size # Load current size of array
sw $t2, array($t3) # Store number in array at index (size)
addi $t3, $t3,1 # Increment array size
sw $t3, array_size # Update array size
j array_menu # Return to array menu
print_array:
# Check if array is empty
lw $t3, array_size # Load current size of array
beqz $t3, print_empty # If size is 0, array is empty
# Print array elements
li $t4,0 # Initialize loop counter to 0
print_loop:
bge $t4, $t3, array_printed # Exit loop if counter >= array size
# Load array element and print
lw $a0, array($t4)
li $v0,1
syscall
addi $t4, $t4,1 # Increment counter
j print_loop
array_printed:
j array_menu # Return to array menu
print_empty:
# Print "Array is empty"
li $v0,4
la $a0, message_empty
syscall
j array_menu # Return to array menu
exit_program:
# Exit program
li $v0,10
syscall
Please show full code.
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

Recommended Textbook for

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions