ARMv8 assembly, How to move value from w register to x register?

4.9k views Asked by At

In ARMv8 assembly, the the compiler would send an error message if I do something like this:

mov    w19,    #16

mov    x20,    w19

How could I move a value from a w register to a x register, and how could I move a value from a x register to a w register?

1

There are 1 answers

0
Shivakumar On

In ARMv8 all you have are 32, 64 bit GPRs which are accessed as 'X' registers. Arm architecture provides instructions to access lower 32 bits of these registers using 'W' names i.e.'W' registers are 32 bit alias of 'X' registers. Architecture doesn't support instructions containing both 'X' and 'W' mnenomincs but either only 'X' or 'W'. When you write to 'W' register, upper 32 bits in 'X' are cleared to zero.

Mov W1, W2       // zero-extend w2 into x1

In above instruction upper 32 bits of W1 are cleared to zero and copies lower 32 bits of W2 into W1.

Mixed register sizes in the same instruction are generally not supported, so instructions like this wouldn't assemble.

Mov X1, W2      // error: mismatched register sizes

There are other variants of Mov instruction like MOVZ, MVN, MOV immediate, MOVK etc. For details of these instruction please refer arm architecture reference manual.