Are there small registers in ARM assembly?

0

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?

assembly
arm
cpu-registers
asked on Stack Overflow May 17, 2014 by tozhan

2 Answers

4

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)

answered on Stack Overflow May 17, 2014 by Notlikethat • edited May 17, 2014 by Notlikethat
2
arm
eor r0, r0
mov r0, #128

why not just do this instead:

mov r0,#128

No reason for the eor...

No you dont have the same 8 bit history with arm, so the registers started off from the beginning as 32 bit. but you still have a number of instructions that help you do sub-32 bit operations on the registers.

answered on Stack Overflow May 18, 2014 by old_timer

User contributions licensed under CC BY-SA 3.0