0

In x86_64 intel nasm assembly you can do

label: .asciz "Something\n"
mov rsi, label

and it will generate

movabs rsi,0x201000

If you use x86_64 intel with gas and write

label: .asciz "Something\n"
mov rsi, label

it will generate

mov    rsi, qword ptr [0x6000db]

which just loads the literal ascii values for the string "Something" into rsi instead of the address for it.

I've tried about a dozen different permutations and can't figure out how replicate the nasm output in gas.

Note: I know I can use lea, mov with rip-relative etc. I'm not asking for a way to get this code to work, I'm asking how to replicate the results from the nasm output.

lanza
  • 1,512
  • 2
  • 13
  • 26
  • You can find out how to do something in GAS syntax by looking at compiler output. e.g. `int var; int *foo() { return &var; }` compiles to `mov eax, OFFSET FLAT:var` https://godbolt.org/g/oH6eH8 – Peter Cordes Jun 26 '18 at 04:55
  • Thanks! But didn't quite work. `movabs esi, offset label` did, however. – lanza Jun 26 '18 at 05:47
  • Are you on OS X or something? Or building PIE executables on Linux? Either way, if `mov esi, OFFSET var` doesn't work, use `lea rsi, [RIP+var]`. A 64-bit absolute immediate is not efficient, so the OFFSET keyword is usually only *useful* when you can use an address as a 32-bit immediate. [Mach-O 64-bit format does not support 32-bit absolute addresses. NASM Accessing Array](https://stackoverflow.com/q/47300844) and the footnote in [32-bit absolute addresses no longer allowed in x86-64 Linux?](https://stackoverflow.com/q/43367427). – Peter Cordes Jun 26 '18 at 06:44

0 Answers0