Probably a common beginner question, and similar questions have been asked on this site, but I can't find any help on a couple points. If you have a 32-bit symbol defined with .word, and you want to load it into register r1, what's the conventional way to do it?
.syntax unified
.cpu cortex-m4
.thumb
/* ... */
_allones: .word 0xffffffff
test:
/* This seems to not work as expected */
ldr r1,_allones @ Value is corrupted/misaligned?
/* Two-line solution */
ldr r1,=_allones @ Loads the address of _allones into r1, not the value itself
ldr r1,[r1] @ Get value proper
My confusion is when you see tutorials like this one where only the ldr r1,=_allones is used to load the value of _allones (see "Initialization Code", first listing and explanation), and the answer I linked above which makes it seem like the first option in my example should work. Target is Cortex-M4, in Thumb mode, with unified syntax.
FWIW The ldr r1,_allones line instead loads the last two bytes of _allones and then the first two bytes of its address in memory, or something in that vain, I haven't looked that closely at the value.