MIPS32:获取地址未在Word边界上对齐

时间:2017-10-03 04:34:34

标签: arrays loops assembly runtime-error mips

我是MIPs编程的新手,我试图使用循环迭代数组来使用系统调用播放midi音符。

运行代码时,我得到错误提取地址未在字边界上对齐。

0x00400038处的运行时异常:地址超出范围0x00000190。

以下是代码:

.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:

0 个答案:

没有答案