Answered step by step
Verified Expert Solution
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
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:
msgexit: asciiz "Exiting the program."
# 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
move $t $v
# Option : Compute series
beq $t $zero, 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
move $t $v
# 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 msgentervalue
syscall
j dealwitharray
displayarray:
# Call subroutine to display array elements
jal displayarraysub
j dealwitharray
exit:
# Print exit message
li $v
la $a msgexit
syscall
# Exit program
li $v
syscall
# Subroutines
computeseriessub:
lis $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
mtc $t $f # Convert integer counter to floatingpoint
div.s $f $f $f # Calculate n
addi $t $t # Increment series counter
j loopseries
endseries:
jr $ra # Return to caller
addtoarraysub:
li $t # Initialize counter for array
lw $t array # Load base address of array
add $t $t $t # Add counter to base address
swc $f$t # Store value in array
jr $ra # Return to caller
displayarraysub:
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 two errors that i got:
rror in line column : lis is not a recognized operator
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