4
votes

i m looking for a way to move any 32 bit constant in arch64 register X1.

Is there a way to perform the equivalent operation of

MOV X1, #imm32

imm32 can be any random 32 bit value like 0xaf41d32c

I know how it can be done in A32 using MOVW and MOVT. I do not want to use LDR X1, =0xaf41d32c, because i am not writing assembly code directly, but instead storing instructions in cache by writing their 32 bit ARM encodings in memory. So i basically cannot form an encoding for LDR X1, =0xaf41d32c.

For eg => According ARMv7 ref manual encoding for a instruction ADD R1, R1, #1 is 0xe2811001. So i store this in I Cache at a location and then start executing from that location.

Do A64 equivalents of MOVW and MOVT exist ? Can you suggest a solution ?

1
why is armv7 tag here?phuclv
I don't know AArch64 but you can load any constant from a literal pool like this (in MIPS but similar approach is also used in ARM, esp. ARM 32)phuclv

1 Answers

4
votes

See movk.

$ echo "long foo() {return 0xaf41d32c;}" | aarch64-linux-android-gcc -O2 -S -o- -xc -
    .cpu generic+fp+simd
    .file   ""
    .text
    .align  2
    .global foo
    .type   foo, %function
foo:
    mov x0, 54060
    movk    x0, 0xaf41, lsl 16
    ret
    .size   foo, .-foo
    .ident  "GCC: (GNU) 4.9 20140827 (prerelease)"
    .section    .note.GNU-stack,"",%progbits