Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please fix my MIPS program: . data msg _ welcome: . asciiz Welcome to main menu msg _ choice: . asciiz Enter 1 to compute

Please fix my 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: "
msg_exit: .asciiz "Exiting the program."
# Array to store user entered values
array: .space 40
.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
move $t0, $v0
# Option 1: Compute series
beq $t0, $zero, exit
beq $t0, $t1, compute_series
# Option 2: Deal with array
beq $t0, $t2, 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,5
syscall
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
move $t0, $v0
# Option 1: Add element to array
beq $t0, $t1, add_to_array
# Option 2: Display array elements
beq $t0, $t2, display_array
# Option 3: Return to main menu
beq $t0, $t3, loop
j deal_with_array
add_to_array:
# Print message to enter value
li $v0,4
la $a0, msg_enter_value
syscall
# Read value from user
li $v0,5
syscall
mtc1 $v0, $f12
# Call subroutine to add element to array
jal add_to_array_sub
# Print success message
li $v0,4
la $a0, msg_enter_value
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
# Exit program
li $v0,10
syscall
# Subroutines
compute_series_sub:
li.s $f0,0 # Initialize sum to 0
li $t4,1 # Counter for the series
li $t5,0 # Counter for 1/n
loop_series:
bge $t5, $f12, end_series # If 1/n >= end of series, exit loop
add.s $f0, $f0, $f1 # Add 1/n to sum
addi $t5, $t5,1 # Increment 1/n counter
mtc1 $t4, $f4 # Convert integer counter to floating-point
div.s $f1, $f1, $f4 # Calculate 1/n
addi $t4, $t4,1 # Increment series counter
j loop_series
end_series:
jr $ra # Return to caller
add_to_array_sub:
li $t6,0 # Initialize counter for array
lw $t7, array # Load base address of array
add $t6, $t6, $t7 # Add counter to base address
swc1 $f12,0($t6) # Store value in array
jr $ra # Return to caller
display_array_sub:
lw $t8, array # Load base address of array
lw $t9,0($t8) # Load first element of array
beqz $t9, array_empty # If first element is 0, array is empty
li $t6,0 # Initialize counter for array
lw $t7, array # Load base address of array
loop_display:
lw $a0,0($t7) # Load element of array
li $v0,1 # Print integer
syscall
addi $t6, $t6,4 # Increment counter by 4(size of integer)
add $t7, $t7, $t6 # Add counter to base address
lw $t9,0($t7) # Load next element of array
bnez $t9, loop_display # If next element is not 0, continue loop
jr $ra # Return to caller
array_empty:
# Print message if array is empty
li $v0,4
la $a0, msg_array_empty
syscall
jr $ra # Return to caller
The two errors that i got:
rror in line 122 column 5: "li.s" is not a recognized operator
Error in line 127 column 14: "$f12": operand is of incorrect type
Assemble: operation completed with errors.

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

Big Data Systems A 360-degree Approach

Authors: Jawwad ShamsiMuhammad Khojaye

1st Edition

0429531575, 9780429531576

More Books

Students also viewed these Databases questions