.data maze: .asciiz “n##########n#*1342171#n#01#####1#n#84#19224#n####1####

Need help with assignments?

Our qualified writers can create original, plagiarism-free papers in any format you choose (APA, MLA, Harvard, Chicago, etc.)

Order from us for quality, customized work in due time of your choice.

Click Here To Order Now

.data
maze: .asciiz “n##########n#*1342171#n#01#####1#n#84#19224#n####1#####n#11#12561#n#16#####1#n#64131281#n##1#######n#2647893E#n##########n”
win_msg: .asciiz “You win!n”
prompt: .asciiz “Enter move (w/a/s/d): ”
invalid_move: .asciiz “Invalid move!n”
current_sum_msg: .asciiz “Current Sum: ”
correct_answers_msg: .asciiz “Correct Answers: ”
final_sum_msg: .asciiz “Final Sum: ”
final_correct_answers_msg: .asciiz “Total Correct Answers: ”
time_msg: .asciiz “Time taken (seconds): ”
newline: .asciiz “n”
sum_prompt: .asciiz “What is the sum of ”
question_mark: .asciiz “?n”
debug_msg: .asciiz “Debug: Reached En”
debug_start_time_msg: .asciiz “Debug: Start time: ”
debug_end_time_msg: .asciiz “Debug: End time: ”
fireworks1: .asciiz “n* * *n * * *n *n * * *n* * *n”
fireworks2: .asciiz “n *n ***n *****n*******n *****n ***n *n”
fireworks3: .asciiz “n *n * *n * *n* *n * *n * *n *n”
beep6: .byte 77
duration6: .byte 500
instrument6: .byte 83
volume6: .byte 100
input_buffer: .space 20
maze_width: .word 10
maze_height: .word 10
player_x: .word 1
player_y: .word 1
current_sum: .word 0
correct_answers: .word 0
start_time: .word 0
end_time: .word 0
.text
main:
# Initialize player position
la $t0, player_x
la $t1, player_y
li $t2, 1
sw $t2, 0($t0)
sw $t2, 0($t1)
# Initialize game stats
la $t3, current_sum
sw $zero, 0($t3)
la $t3, correct_answers
sw $zero, 0($t3)
# Get start time
li $v0, 30
syscall
la $t4, start_time
sw $v0, 0($t4)
# Debug start time
la $a0, debug_start_time_msg
li $v0, 4
syscall
lw $a0, start_time
li $v0, 1
syscall
# Print newline
la $a0, newline
li $v0, 4
syscall
# Print initial maze
la $a0, maze
li $v0, 4
syscall
# Display initial sum and correct answers
jal display_stats
game_loop:
# Load player position
lw $t0, player_x
lw $t1, player_y
# Calculate player position in the maze string
la $t9, maze
li $t4, 11 # Each row is 11 characters including newline
mul $t5, $t0, $t4 # Row offset
add $t5, $t5, $t1 # Column offset
add $t5, $t5, $t9 # Final address in maze string
# Restore original maze character (if not starting position)
bne $t0, 1, not_starting_pos
bne $t1, 1, not_starting_pos
j skip_restore
not_starting_pos:
li $t6, ‘ ‘ # Assuming empty space
sb $t6, 0($t5)
skip_restore:
# Prompt for move
la $a0, prompt
li $v0, 4
syscall
# Read user input
li $v0, 12
syscall
move $t3, $v0
# Validate user input
li $t7, ‘w’
li $t8, ‘a’
li $t9, ‘s’
li $t0, ‘d’
beq $t3, $t7, process_input
beq $t3, $t8, process_input
beq $t3, $t9, process_input
beq $t3, $t0, process_input
j invalid
process_input:
# Calculate new position based on input
lw $t0, player_x
lw $t1, player_y
move $t4, $t0
move $t5, $t1
beq $t3, ‘w’, move_up
beq $t3, ‘a’, move_left
beq $t3, ‘s’, move_down
beq $t3, ‘d’, move_right
move_up:
sub $t4, $t0, 1
j validate_move
move_down:
add $t4, $t0, 1
j validate_move
move_left:
sub $t5, $t1, 1
j validate_move
move_right:
add $t5, $t1, 1
j validate_move
validate_move:
# Check boundaries
lw $t6, maze_width
lw $t7, maze_height
bltz $t4, invalid
bltz $t5, invalid
bge $t4, $t7, invalid
bge $t5, $t6, invalid
# Calculate maze index
li $t8, 11 # Each row is 11 characters including newline
mul $t8, $t8, $t4 # Row offset
add $t8, $t8, $t5 # Column offset
# Check maze value at new position
la $t9, maze
add $t9, $t9, $t8
lb $t9, 0($t9)
# Debug print to show the character at the new position
move $a0, $t9
li $v0, 11 # Print character at new position
syscall
# Check if move is valid
beq $t9, ‘#’, invalid
# Update player position
sw $t4, player_x
sw $t5, player_y
# Check if player reached the end
beq $t9, ‘E’, win
# Prompt for sum input if moving to a number
sub $t6, $t9, ‘0’ # Convert character to number
bltz $t6, skip_update
bgt $t6, 9, skip_update
# Display the question “What is the sum of X?”
la $a0, sum_prompt
li $v0, 4
syscall
# Display the number
move $a0, $t6
add $a0, $a0, ‘0’ # Convert to ASCII character
li $v0, 11
syscall
# Display the question mark
la $a0, question_mark
li $v0, 4
syscall
# Read sum input as a string
la $a0, input_buffer
li $a1, 20
li $v0, 8
syscall
# Parse and evaluate the input
la $t0, input_buffer
# Read first number
lb $t1, 0($t0)
sub $t1, $t1, ‘0’ # Convert ASCII to integer
# Skip ‘+’ character
lb $t2, 1($t0)
beq $t2, ‘+’, skip_plus
j invalid
skip_plus:
# Read second number
lb $t2, 2($t0)
sub $t2, $t2, ‘0’ # Convert ASCII to integer
# Calculate the sum of the input numbers
add $t3, $t1, $t2
# Check if the sum is correct
lw $t8, current_sum
add $t8, $t8, $t6
bne $t3, $t6, invalid
# Update current sum and correct answers if correct
sw $t8, current_sum
lw $t7, correct_answers
addi $t7, $t7, 1
sw $t7, correct_answers
# Play sound for correct answer
la $a0, beep6
la $a1, duration6
la $a2, instrument6
la $a3, volume6
# Load the value of “beep” into $a0
lb $a0, 0($a0)
lb $a1, 0($a1)
lb $a2, 0($a2)
lb $a3, 0($a3)
# Make the system call to play the sound
li $v0, 31
syscall
# Display fireworks
jal display_fireworks
skip_update:
# Calculate the new position in the maze string
la $t9, maze
lw $t0, player_x
lw $t1, player_y
li $t4, 11 # Each row is 11 characters including newline
mul $t5, $t0, $t4 # Row offset
add $t5, $t5, $t1 # Column offset
add $t5, $t5, $t9 # Final address in maze string
# Update the player’s position in the maze
li $t6, ‘*’
sb $t6, 0($t5)
# Print maze
la $a0, maze
li $v0, 4
syscall
# Display current sum and correct answers
jal display_stats
j game_loop
invalid:
la $a0, invalid_move
li $v0, 4
syscall
j game_loop
win:
# Get end time
li $v0, 30
syscall
la $t4, end_time
sw $v0, 0($t4)
# Debug end time
la $a0, debug_end_time_msg
li $v0, 4
syscall
lw $a0, end_time
li $v0, 1
syscall
# Print newline
la $a0, newline
li $v0, 4
syscall
# Debug message to indicate we have reached the win condition
la $a0, debug_msg
li $v0, 4
syscall
# Display win message
la $a0, win_msg
li $v0, 4
syscall
# Display final sum
la $a0, final_sum_msg
li $v0, 4
syscall
lw $a0, current_sum
li $v0, 1
syscall
# Print newline
la $a0, newline
li $v0, 4
syscall
# Display final correct answers count
la $a0, final_correct_answers_msg
li $v0, 4
syscall
lw $a0, correct_answers
li $v0, 1
syscall
# Print newline
la $a0, newline
li $v0, 4
syscall
# Calculate and display time taken
la $t4, start_time
lw $t0, 0($t4)
la $t4, end_time
lw $t1, 0($t4)
sub $t2, $t1, $t0 # Calculate elapsed time
la $a0, time_msg
li $v0, 4
syscall
move $a0, $t2
li $v0, 1
syscall
# Print newline
la $a0, newline
li $v0, 4
syscall
j end_game
display_stats:
# Display current sum
la $a0, current_sum_msg
li $v0, 4
syscall
lw $a0, current_sum
li $v0, 1
syscall
# Display correct answers count
la $a0, correct_answers_msg
li $v0, 4
syscall
lw $a0, correct_answers
li $v0, 1
syscall
# Print newline
la $a0, newline
li $v0, 4
syscall
jr $ra
display_fireworks:
# Generate a random number
li $v0, 42 # Random number syscall
syscall
# Make sure the random number is positive
abs $v0, $v0 # Absolute value
# Ensure the random number is within bounds
li $t1, 3
rem $t0, $v0, $t1 # Get a value between 0 and 2
beq $t0, 0, fireworks1_display
beq $t0, 1, fireworks2_display
j fireworks3_display
fireworks1_display:
la $a0, fireworks1
li $v0, 4
syscall
j fireworks_end
fireworks2_display:
la $a0, fireworks2
li $v0, 4
syscall
j fireworks_end
fireworks3_display:
la $a0, fireworks3
li $v0, 4
syscall
fireworks_end:
jr $ra
end_game:
# End the game by exiting the program
li $v0, 10
syscall
i have this code is a maze game project i add a sound code and whenit ask me the sum of number and i answer it i get error
but if i take the sound code of it works. CAN YOU FIX THE CODE ?

Need help with assignments?

Our qualified writers can create original, plagiarism-free papers in any format you choose (APA, MLA, Harvard, Chicago, etc.)

Order from us for quality, customized work in due time of your choice.

Click Here To Order Now