as a hobby I'm trying to learn ARM assembly after briefly seeing it years ago in College.
I modified a little pseudo Hello World program (found in a book) this way :
.global _start
_start: ldr R1,=msgtxt
mov R2,#11
bl v_asc
mov R0,#0
mov R7,#1
svc 0
.text
v_asc: mov R0,#1
mov R7,#4
svc 0
bx LR
.end
.data
msgtxt: .ascii "Yeah Baby!\n"
LD throws the following error :
prog.o: In function
v_asc': (.text+0x1c): undefined reference tomsgtxt'
Simply putting the .data section above the .text one makes it work like a charm. But then, _start is still above .data :
.global _start
_start: ldr R1,=msgtxt
mov R2,#11
bl v_asc
mov R0,#0
mov R7,#1
svc 0
.data
msgtxt: .ascii "Yeah Baby!\n"
.text
v_asc: mov R0,#1
mov R7,#4
svc 0
bx LR
.end
But this confuses me :
Why is LD pretending the reference is in v_asc while it is in _start? How come the line "ldr R1,=msgtxt" does not throw an undefined reference?
Thanks by advance.
.endas that will be ignored. The order of your blocks does not matter. As for the misleading message, that's just because=instructs the assembler to place the constant into a literal pool and that happens to be located afterv_asc. - Jester