Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please fix the four errors in my MIPS program: . data msg _ welcome: . asciiz Welcome to main menu msg _ choice: . asciiz

Please fix the four errors in 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: "
# 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
add $t0, $v0, $zero
# Option 1: Compute series
beqz $t0, 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
add $t0, $v0, $zero
# 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_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
li $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
div.s $f1, $f1, $t4 # Calculate 1/n
addi $t4, $t4,1 # Increment series counter
j loop_series
end_series:
jr $ra # Return to caller
add_to_array_sub:
# Add your logic here to add the value in $f12 to the array
li $t6,0 # Initialize counter for array
lw $t7, array # Load base address of array
add $t6, $t6, $t7 # Add counter to base address
sw $f12,0($t6) # Store value in array
jr $ra # Return to caller
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
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 following errors that i got in my mars program:
Error in line 121 column 8: "$f0": operand is of incorrect type
Error in line 125 column 14: "$f12": operand is of incorrect type
Error in line 128 column 21: "$t4": operand is of incorrect type
Error in line 140 column 8: "$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_2

Step: 3

blur-text-image_step3

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