Beginner ARM Assembly Question
11,451
You can use ldrb
to load a single byte into a register from a byte-aligned pointer. I expect that's what you're looking for:
ldr r0, =val
ldrb r1, [r0]
You probably want the same in your loop or else you'll crash in the same way once you advance to the first character at a non-word-aligned address (probably the o
in How
):
loop: ldrb r2, [r0]
Author by
Admin
Updated on June 04, 2022Comments
-
Admin almost 2 years
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
-
Admin about 13 yearsI am not clear what you mean by 'padding the address of the byte.'
-
Warren Stevens about 13 yearsyou must be to the align - alignment - padding -> allignment
-
Carl Norum about 13 yearsI'm not sure your answer or comment make any sense. Certainly the alignment of
msg
andval
in the data section is not the OP's problem. -
Carl Norum about 13 years@Michael Burr, I meant as opposed to a pointer with any more restrictive alignment.