4

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 ?

auselen
  • 27,577
  • 7
  • 73
  • 114
jkg
  • 101
  • 1
  • 3
  • 7
  • why is [tag:armv7] tag here? – phuclv Jan 14 '15 at 09:22
  • I don't know AArch64 but you can load any constant from a [literal pool](http://en.wikipedia.org/wiki/Literal_pool) like [this](http://stackoverflow.com/questions/3914210/loading-an-address-in-mips64/6507814#6507814) (in MIPS but similar approach is also used in ARM, esp. ARM 32) – phuclv Jan 14 '15 at 09:27

1 Answers1

5

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
auselen
  • 27,577
  • 7
  • 73
  • 114