unaligned address error checking in MIPS 0x10010072 [duplicate]
I get an error when I run the program: store address not aligned on word boundary, What should I do?
Here's the code:
.data
welcome: .asciiz "Welcome to Memorization Game. \n\nYour need to enter the numbers printed in the exact sequence. Press S to start.\n"
start: .asciiz "\nHere we go....\n"
enter: .asciiz "\n Please enter the number:\n"
array: .space 400
.text
main: la $t0, array # load address of array
la $a0, welcome
li $v0, 4 #
syscall # print welcome message
li $v0, 12 #
syscall # scan to continue
bne $v0, 115, Exit # if $v0 != "s", jump to Exit
la $a0, start #
li $v0, 4 #
syscall # Print start message
li $s0, 0 # N0. of random generated numbers = 0
add $t3, $t0, $0 # load address of array into $t3
Random: slti $t2, $s0, 100 #
beqz $t2, Exit #
addi $a0, $zero, 10 #
addi $a1, $zero, 99 #
li $v0, 42 #
syscall # generate a random number
sw $v0, ($t3) # put number generated into array[n]
addi $t3, $t3, 4 # next address
addi $s0, $s0, 1 # counter++
j Random
Exit: li $v0, 10 #
syscall # terminate
Solution 1:
Try inserting one of the following before array: .space 400
:
.p2align 2
.align 2
.align 4
Another possible option is to move array: .space 400
to the beginning of the data section.