Search code examples
linuxassemblycompiler-errorsintelatt

Error when using GAS with .intel_syntax


According to some documentation and this answer, it is possible to use GAS in Linux with the Intel syntax instead of the default AT&T syntax.

I tried to compile the following simple code, contained in a dedicated file file.s:

.intel_syntax noprefix

section .data

section .text
        global _start

_start:
        mov eax, 1      # some random comments

        mov ebx, 0      

        int 80h         

If I run as file.s -o file.o, the following error is produced:

is2_exit.s: Assembler messages:
is2_exit.s:3: Error: no such instruction: `section .data'
is2_exit.s:5: Error: no such instruction: `section .text'
is2_exit.s:6: Error: no such instruction: `global _start'
is2_exit.s:13: Error: junk `h' after expression

It seems that the .intel_syntax is not considered at all. What's wrong?


Solution

  • You appear to be using NASM syntax for some of the directives, as well as a hexadecimal literal. You need to change those to use GNU AS syntax.

    Instead of section name you should use .section name (with a leading dot). In the case of .section .text and .section .data you can simplify those into .text and .data.

    Similarly, global symbol should be .global symbol (or .globl symbol) in GNU AS syntax.


    Regarding hexadecimal literals, the manual has this to say:

    A hexadecimal integer is '0x' or '0X' followed by one or more hexadecimal digits chosen from `0123456789abcdefABCDEF'.

    So 80h should be written 0x80 (or 0X80).