Answered step by step
Verified Expert Solution
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
msgwelcome: asciiz "Welcome to main menu"
msgchoice: asciiz "Enter to compute the series
Enter to deal with array
Enter to end the program"
msgsubchoice: asciiz "Enter to add an element to the array
Enter to display the array elements
Enter to return to the main menu"
msgarrayempty: asciiz "Array is empty"
msgendseries: asciiz "Enter the end of series:
msgentervalue: asciiz "Enter the value:
msgsumis: asciiz "Sum is:
# Array to store user entered values
array: space
text
main:
# Print welcome message
li $v
la $a msgwelcome
syscall
loop:
# Print menu choices
li $v
la $a msgchoice
syscall
# Read user choice
li $v
syscall
add $t $v $zero
# Option : Compute series
beqz $t exit
beq $t $t computeseries
# Option : Deal with array
beq $t $t dealwitharray
j loop
computeseries:
# Print message to enter end of series
li $v
la $a msgendseries
syscall
# Read end of series value from user
li $v
syscall
mtc $v $f
# Call subroutine to compute series and store result in $f
jal computeseriessub
# Print message and result
li $v
la $a msgsumis
syscall
mfc $a $f
li $v
syscall
j loop
dealwitharray:
# Print sub menu choices
li $v
la $a msgsubchoice
syscall
# Read user choice
li $v
syscall
add $t $v $zero
# Option : Add element to array
beq $t $t addtoarray
# Option : Display array elements
beq $t $t displayarray
# Option : Return to main menu
beq $t $t loop
j dealwitharray
addtoarray:
# Print message to enter value
li $v
la $a msgentervalue
syscall
# Read value from user
li $v
syscall
mtc $v $f
# Call subroutine to add element to array
jal addtoarraysub
# Print success message
li $v
la $a msgvalueadded
syscall
j dealwitharray
displayarray:
# Call subroutine to display array elements
jal displayarraysub
j dealwitharray
exit:
# Print exit message
li $v
la $a msgexit
syscall
li $v
syscall
# Subroutines
computeseriessub:
# Add your logic here to compute the series based on the value in $f and store the result in $f
li $f # Initialize sum to
li $t # Counter for the series
li $t # Counter for n
loopseries:
bge $t $f endseries # If n end of series, exit loop
add.s $f $f $f # Add n to sum
addi $t $t # Increment n counter
div.s $f $f $t # Calculate n
addi $t $t # Increment series counter
j loopseries
endseries:
jr $ra # Return to caller
addtoarraysub:
# Add your logic here to add the value in $f to the array
li $t # Initialize counter for array
lw $t array # Load base address of array
add $t $t $t # Add counter to base address
sw $f$t # Store value in array
jr $ra # Return to caller
displayarraysub:
# 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 $t array # Load base address of array
lw $t$t # Load first element of array
beqz $t arrayempty # If first element is array is empty
li $t # Initialize counter for array
lw $t array # Load base address of array
loopdisplay:
lw $a$t # Load element of array
li $v # Print integer
syscall
addi $t $t # Increment counter by size of integer
add $t $t $t # Add counter to base address
lw $t$t # Load next element of array
bnez $t loopdisplay # If next element is not continue loop
jr $ra # Return to caller
arrayempty:
# Print message if array is empty
li $v
la $a msgarrayempty
syscall
jr $ra # Return to caller
The following errors that i got in my mars program:
Error in line column : $f: operand is of incorrect type
Error in line column : $f: operand is of incorrect type
Error in line column : $t: operand is of incorrect type
Error in line column : $f: operand is of incorrect type
Assemble: operation completed with errors.
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