www.delorie.com/djgpp/v2faq/faq17_1.html   search  
Node:Syntax, Next:, Previous:Converting, Up:Converting

17.1 GCC/Gas won't accept valid assembly code ...

Q: I have some code written in assembly which compiles under MASM and TASM, but GCC gives me a long list of error messages.

A: The GNU Assembler (as.exe), or Gas, called by GCC accepts the AT&T syntax, which is different from the Intel syntax. Notable differences between the two syntaxes are:

Examples:

    Intel:  [ebp - 4]         AT&T:  -4(%ebp)
    Intel:  [foo + eax*4]     AT&T:  foo(,%eax,4)
    Intel:  [foo]             AT&T:  foo(,1)
    Intel:  gs:foo            AT&T:  %gs:foo

For a complete description of the differences, see GNU assembler documentation. If you don't read this FAQ with an Info browser, download GNU Binutils, unzip the files named as.iN (where N is a digit) from it, then type at the DOS prompt:

 info as machine i386

You will see a menu of Gas features specific to x86 architecture.

A user guide for inline assembly was written by Brennan Underwood; it describes how to use inline assembly programming with DJGPP and includes a tutorial on the AT&T assembly syntax. Check out the DJGPP inline assembly tutorial.

Another useful tutorial about writing separate assembly-language modules for DJGPP was written by George Foot and is available from George's home page.

The DJGPP User's Guide also has a tutorial on writing assembly-language code. One of the sections there describes the CPU architecture, which is geared towards assembly-language programming.

Yet another tutorial on the subject of inline assembly is available at <http://www.castle.net/~avly/djasm.html>.

Many people who used Intel syntax and then converted to the AT&T style say that they like the AT&T variant more. However, if you prefer to stick with the Intel syntax, download and install NASM, which is a free portable assembler. It is compatible with DJGPP and accepts a syntax which is much more similar to the Intel style. A guide for using NASM with DJGPP was written by Matthew Mastracci and is available from Matthew's Web page.

Note that Binutils maintainers are working on adding an option to Gas which will cause it accept the Intel syntax as well, so it is most probable that beginning with Binutils 2.10, Gas will have this feature.



  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2001   by Eli Zaretskii     Updated Apr 2001