I have tried changing so much of this code but I keep getting either neverending Arithmetic Overflow warnings or 'Bad address in data/stack' errors. I can't seem to get it properly right! Any insight is welcome! I am trying to implement a sudoku board and these are the instructions for this function: Given a pointer to a Sudoku board, this function should return an integer indicating how many of the cells in the board have been solved. The state of the board should be unmodified. Each Sudoku cell occupies ten bytes in all. And with each cell occupying 10 bytes, the whole board occupies 810 bytes of memory.
Any insight?
# a0: pointer to board
# v0: number of solved cells
count_solved_cells:
li $v0, 0 # Initialize count to 0
la $s0, board # Load the address of the board to $s0
li $t0, 81 # Initialize loop counter
count_cells_loop:
jal is_cell_solved # Check if the current cell is solved
addi $v0, $v0, 1 # Increment count regardless of cell status
addi $s0, $s0, 10 # Move to the next cell (each cell is 10 bytes)
addi $t0, $t0, -1 # Decrement loop counter
bnez $t0, count_cells_loop # If not reached the end of the board, continue the loop
jr $ra
It seems like there's an issue in your loop where you're incrementing the count regardless of the cell status. You should only increment the count if the cell is solved. Also, you need to properly handle the return value from the is_cell_solved function.
Here's a modified version of your code:
This modification includes a branch (not_solved) to skip the increment of the count if the cell is not solved. Ensure that the is_cell_solved function properly returns a value indicating whether the cell is solved or not.