I would like to use the ldrb instruction to load a single byte from memory into a register. However, this does not seem possible if the 2nd operand is a label. A complete minimal reproducible commented example:
// GNU Assembly, aarch64 Linux
.data
.equ SYS_EXIT, 93
.equ SUCCESS, 0
CHAR:
.byte 1
.text
.global _start
_start:
// none of these work, but why?
// ldrb w19, CHAR // invalid addressing mode at operand 2
// ldrb w19, =CHAR // invalid addressing mode at operand 2
// ldrb w19, [CHAR] // 64-bit integer or SP register expected at operand 2
// ldr w19, CHAR // loads 4 bytes instead of 1 byte
// I have to do this but it's verbose and clunky
ldr x20, =CHAR
ldrb w19, [x20]
// is there any way to coalesce the above 2 instructions into 1?
mov x8, SYS_EXIT
mov x0, SUCCESS
svc 0
Ideally I'd like to write ldrb <reg>, <label>, e.g. ldrb w19, CHAR, and have it just load a single byte from CHAR's memory address like I would expect, instead of throwing an assembler error.
