Reputation: 4321
GNU ARM assembler supports prefixes to extract group of bytes from a relocation value https://sourceware.org/binutils/docs/as.html#ARM_002dRelocations
On ARMv7m and later, the low/high 16 bit operators work fine, including with literal numbers not just symbol addresses.
movw r0, #:lower16:0xabadcafe
movt r0, #:upper16:0xabadcafe
But I cannot manage to get the 8 bits prefixes working with literals, on any arch (v6m, v7m, v8m):
.thumb
.text
test:
movs r0, #:upper8_15:0xabadcafe
Compiling this code returns an error; which is weird to me because the prefix is apparently ok with the parser (I was expecting a bad expression
error), but instead is just doing nothing as the full 32 bits value is considered by the movs
instruction.
$ ./arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi/bin/arm-none-eabi-gcc -o test -mcpu=cortex-m23 -march=armv8-m.base -mthumb -mpure-code -c test.S
test.S: Assembler messages:
test.S:5: Error: invalid immediate: -1414673666 is out of range
test.S:5: Error: value of abadcafe too large for field of 2 bytes at 00000000
I made some research online and apparently this is supposed to work; the snippet in https://www.mail-archive.com/[email protected]/msg230076.html is exactly what I want to achieve on v6m: loading a register without any data access using the prefix feature of the assembler.
Upvotes: 1
Views: 401