armarmv8

Adding 32 bit register to 64 bit register in ARM


I have code something like this:

mov x24, 5
mov w25, 5
add x24, x24, w25

I am getting a "Missing extend operator at operand 3". I know I could just switch both to 64bit operators but I'm wondering if its still possible to add 32bit numbers and 64bit numbers together like the above


Solution

  • You have to put the optional extend operator
    unsigned:

    add x24, x24, w25, uxtw
    

    signed:

    add x24, x24, w25, sxtw
    

    The extension can be:

    uxtb: unsigned 8bit
    sxtb: signed 8bit
    uxth: unsigned 16bit
    sxth: signed 16bit
    uxtw: unsigned 32bit
    sxtw: signed 32bit