Search code examples
assemblyx86gnu-assembler

How do you specify a label reference using .intel_syntax?


I'm having some really big problems trying to get certain x86 instructions assembled properly using .intel_syntax, compiling with -m32 (i.e. 32-bit mode). If I have some code like this:

    #define STACK_SIZE                      0x4000

    .att_syntax
    movl    $(stack + STACK_SIZE), %esp

    .comm   stack, STACK_SIZE

...all is fine. The decompiled output from this looks like this (AT&T syntax first, Intel syntax shown afterwards).

100010:       bc 70 5a 10 00          mov    $0x105a70,%esp
100010:       bc 70 5a 10 00          mov    esp,0x105a70

However, if I change my code like this (which I feel "should" work):

    .intel_syntax noprefix
    mov     esp, stack + STACK_SIZE

...I get this output instead:

100010:       8b 25 70 5a 10 00       mov    0x105a70,%esp
100010:       8b 25 70 5a 10 00       mov    esp,DWORD PTR ds:0x105a70

Obviously, this is wrong; I'm not trying to dereference the stack label but instead create a reference to it.

For now, my workaround is to use AT&T syntax for some parts of my file and Intel syntax for the rest. This feels like a kludge. Unfortunately, the information about GAS Intel mode feels a bit sparse; this page gave some hints but nothing that really helped.

Many thanks in advance. If I had reputation enough to give you a bounty, I would. :)


Solution

  • That seems right. You are correct that there isn't too much information on .intel_syntax. I wrote to a gal whose name I found in the source code, asking if there was any documentation. She replied that there wasn't, that she'd just reverse engineered some stuff they got from Intel. I poked around the source and found that offset flat: was required (at that time) - the colon was mandatory, too! Now, just plain offset seems to work... and there may be more documentation available, too(?).

    I should think that Nasm would work with the same toolchain... no?