简体   繁体   中英

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

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 aw register to ax register, and how could I move a value from ax register to aw register?

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 ie'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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM