assemblycpu-registersarm64mov

how to load an immediate value to the register in arm64?


I want to load an immediate value (0x48f0d0) to the register x0, but I have an error "Assembler messages:

/tmp/ccUzTnfa.s:257: Error: immediate cannot be moved by a single instruction"

this is the instruction I used:

mov x0, #0x48f0d0

Solution

  • Only certain constants can be expressed as immediate operands on ARM64. To work around this restriction, either load from a literal pool

    ldr x0, =0x48f0d0
    

    or use a movz/movk pair:

    movz x0, #0xf0d0
    movk x0, #0x48, lsl #16