How do you properly load the value of a predefined .byte into a register? e.g. With a constant defined as:
constant: .byte 'a'
I am trying:
ldr r0, =constant
ldr r1, [r0]
However, the simulator halts after the second line and gives the error "Access to unaligned memory location, bad address" The rest of the code otherwise runs fine as long as the second line is not included.
Full Code:
; 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