Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there small registers in ARM assembly?

I recently started playing with ARM assembly and notice I only seem to be about to move 32 bit values into registers but what if i wanted to only move 8 or 16 bits into the registers like in x86 assembly. i.e.

arm
eor r0, r0
mov r0, #128

x86
xor eax, eax
mov al, 0x80

r0 now contains 0x80 but it is a 32 bit register so it will contain 0x00000080

if this was x86 i could use al (8 bit register) to manipulate the last byte instead of eax (32 bit register).

tl;dr Are there small registers in ARM assembly?

like image 730
tozhan Avatar asked Oct 26 '25 21:10

tozhan


1 Answers

No. ARM registers are 32-bit1.

However, assuming you're on a recent enough architecture version (ARMv6T2 or later) you can use the BFI and UBFX instructions to insert/extract an arbitrary slice of a register from/to the bottom of another without affecting the other bits. Doing the same with an immediate operand is a little trickier since MOV zero-extends immediates2 (i.e. the eor r0,r0 in your example is entirely redundant) - you'd either have to use AND and ORR as mentioned, or use an intermediate register for MOV followed by BFI.


[1] Well, "fixed-size" is more appropriate once you consider AArch64 state - there you have 32-bit and 64-bit views of the same registers, but any writes to a 32-bit view implicitly zero the upper 32 bits, so the same principle still applies (i.e. it doesn't allow you to pretend you have twice as many half-sized registers like an 8086).

[2] The exception to this is MOVT, which loads an immediate into the upper 16 bits of a register without touching the lower half (to allow loading a full 32-bit immediate with a MOVW/MOVT pair)

like image 173
Notlikethat Avatar answered Oct 29 '25 18:10

Notlikethat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!