MIPS32: Fetch Address Not Aligned on Word Boundary

0

I'm new to MIPs programming and i'm trying to iterate through an array using a loop to play midi notes using syscall.

When running the code, I get the error fetch address not aligned on word boundary.

Runtime exception at 0x00400038: address out of range 0x00000190.

Here is the code:

.data 
my_notes: .word 39, 44, 47, 46, 44, 51, 49, 46, 44, 47, 46, 42, 45, 39, 39, 44, 47, 46, 44, 51, 54, 53, 52, 48, 52, 51, 50, 38, 47, 44  
note_durations: .word 400, 400, 400, 400, 800, 400, 1200, 1200, 400, 400, 400, 800, 400, 2000, 400, 400, 400, 400, 800, 400, 800, 400, 800, 400, 400, 400, 400, 800, 400, 2000
iterator:  .word 0
arraySize: .word 30

.text 
main:
la $t0, my_notes
lw $t1, iterator
lw $t2, arraySize
lw $t3, note_durations

loop:
bgt $t1, $t2, end   # if (iterator > arraySize) goto end
sll $t4, $t1, 2     # 4*i
addu $t6, $t4, $t3  # $t6 = note duration memory address + 4i
addu $t4, $t4, $t0  # $t4 = note memory address + 4i
lw $t5, 0($t4)      # store in $t5 memory address of note[4i]
lw $t7, 0($t6)      # store in $t7 memory address of note_duration[4i]

li $v0, 33          # Load service number to play a note
la $a0, ($t5)        # pitch
la $a1, ($t7)       # duration
la $a2, 1       # instrument
la $a3, 80      # volume
syscall 
addi $t1, $t1, 1     # iterate +1
j loop

end:
arrays
loops
assembly
runtime-error
mips
asked on Stack Overflow Oct 3, 2017 by Antoine Vo • edited Oct 3, 2017 by Antoine Vo

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0