The AArch64 processor (aka arm64), part 2: Extended register operations

Raymond Chen

There are a number of places where the instruction set permits the value in a register to be transformed before it is used. The set of valid transforms vary from instruction to instruction, but they share a common syntax.

ShiftedRn/zr, LSL #nLogical shift left.
Rn/zr, LSR #nLogical (unsigned) shift right.
Rn/zr, ASR #nArithmetic (signed) shift right.
ExtendedWn/sp, UXTB #nUnsignedextend low byteshifted left.
Wn/sp, UXTH #nUnsignedextend low halfwordshifted left.
Wn/sp, UXTW #nUnsignedextend low wordshifted left.
Xn/sp, UXTX #nUnsignedextend low doublewordshifted left.
Wn/sp, SXTB #nSignedextend low byteshifted left.
Wn/sp, SXTH #nSignedextend low halfwordshifted left.
Wn/sp, SXTW #nSignedextend low wordshifted left.
Xn/sp, SXTX #nSignedextend low doublewordshifted left.

The LSL, LSR, and ASR transformations are formally known as shifted registers. They take a value in a register and shift it.

The extend+shift transformations are formally known as extended registers. They extract a subset of the source register, extend it either as a signed or unsigned value to the full operand size, and then shift the extended result.

Shifting the zero register isn’t particular useful since you still get zero, but the instruction encoding lets you do it. Similarly, there is no practical difference between UXTX and SXTX (unsigned and signed extension of the low doubleword of a 64-bit register) since the low doubleword of a 64-bit register is the whole register.

For extended registers, the assembler lets you omit the shift amount, in which case it defaults to zero. The shift amount is not optional for the shifted registers.

Before you get all excited about the possibilities, know that not all instructions support all of these transformations, and for the ones that they do, the shift amounts are limited. We’ll look at the restrictions as they arise. For now, I just wanted to introduce the concepts.

As a convenience, if you are using an instruction that accepts only extended registers, but you want to use a LSL, you can write LSL #n, and the assembler will autoconvert it to UXTW #n or UXTX #n, depending on the operand size.

Next time, we’ll start putting these transforms to use when we look at addressing modes.