3

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?

Community
  • 1
  • 1
BowPark
  • 1,340
  • 2
  • 21
  • 31
  • 3
    How about if you use `.data`, `.text`, `.global _start` and `0x80`? – Michael Mar 16 '16 at 11:22
  • 2
    The `intel_syntax` does not apply to directives, especially since there is no single intel syntax. They are different in each assembler. – Jester Mar 16 '16 at 11:23
  • @Michael yes, you are right! If you want to write an answer, I will choose it. – BowPark Mar 16 '16 at 14:06
  • @Jester I didn't know it. By changing the directives syntax it gives no errors in fact. – BowPark Mar 16 '16 at 14:07
  • I'd recommend something else for doing assembler programming. gas is not that well suited for this. Try [yasm](http://yasm.tortall.net), [fasm](http://flatassembler.net) or [nasm](http://www.nasm.us) instead. – Nikos C. Mar 16 '16 at 15:13
  • Is there one file out there using Intel syntax which *can* compile using current versions of both NASM and GAS (via .intel_syntax)? – user2023370 Mar 03 '18 at 12:14

1 Answers1

2

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).

Michael
  • 57,169
  • 9
  • 80
  • 125