MIPS:绘制位图时存储地址未在字边界上对齐

MIPS: store address not aligned on word boundary when painting a bitmap

我有这个代码:

.data
FP: .space 1048576 #firstposition of a 16x16 (w/h in pixels), 512x512 bitmap
colorred: .word 0x007f0000

.text

lw $s1, colorred
la $s2, FP

li $v0, 42
la $a1, 62
syscall
move $t0, $a0  #get a random integer and place it in t

li $v0, 42
la $a1, 62
syscall
move $t1, $a0

mul $t1, $t0, $t1
sw  $s1, FP($t1)

li $v0, 10
syscall

而且我不断收到此错误: 第 21 行:0x0040003c 处的运行时异常:存储地址未在字边界 0x1001020a

上对齐

有时它确实起作用并在位图中绘制了一点,但有时它不起作用

这是问题所在:

sw  $s1, FP($t1)

您的代码中没有任何内容可以确保 $t1 在字边界上对齐。使用前需要清空$t1的低两位,如:

li  $t2, 0xfffffffc
and $t1, $t1, $t2
sw  $s1, FP($t1)