0

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
Matt
  • 22,721
  • 17
  • 71
  • 112
  • More detail re: how `.align` works in classic MIPS assemblers (which MARS/SPIM follow, unlike clang and the GNU assembler targeting MIPS): [MIPS Assembly Alignment Align n](https://stackoverflow.com/q/41359415) – Peter Cordes Jan 11 '22 at 02:40

1 Answers1

3

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.

Alexey Frunze
  • 61,140
  • 12
  • 83
  • 180
  • Thanks, that solved the problem, but I don't think the randomly generated numbers are being stored. Any suggestions ? – Mohammad Momani Apr 20 '13 at 13:00
  • Yes, use a debugger. Also, since this issue is resolved, the rest deserves a separate question. But do debug before posting new questions. – Alexey Frunze Apr 20 '13 at 13:07