【发布时间】:2011-02-08 04:23:51
【问题描述】:
如何正确地将预定义 .byte 的值加载到寄存器中?例如常量定义为:
constant: .byte 'a'
我正在尝试:
ldr r0, =constant
ldr r1, [r0]
但是,模拟器在第二行之后停止并给出错误“访问未对齐的内存位置,错误地址”只要不包括第二行,其余代码就可以正常运行。
完整代码:
; r0 is a pointer to msg1
; r1 used to store the value of val
; r2 used to compare a character in msg1
; r3 counter for the number of comparisons
.text
.global _start
_start:
ldr r0, =msg
ldr r1, =val
ldr r1, [r1]
mov r3, #0
loop: ldr r2, [r0]
cmp r2, #0
beq done
cmp r0, r1
add r0, r0, #4
bne loop
add r2, r2, #1
b loop
done:
swi 0x11
.data
.align
msg: .asciz "How many 'a's are in this string?"
val: .byte 'a'
.end
【问题讨论】: