www.delorie.com/djgpp/faq/converting/asm.html   search  
I have some code written in assembly which compiles under MASM and TASM, but gcc gives me a long list of error messages.

First off, do not trust gas! Check that it does what you expected it to. To be almost safe follow these guidelines:

  1. Use explicit sizing, i.e., use "movl" not "mov" even if you think the arguments are clearly 32-bit. The fact that you are using byte registers doesn't seem to matter.
  2. Code segment overrides as byte constants, not as "%cs:". According to Charles Sandmann gas uses the phase of the moon in deciding whether to ignore your prefixes.
  3. Make sure the operands match the instruction, don't just assume you will get an error message.
To emphasize: gas at current can be trusted only to compile assembler code produced by gcc correctly. All other code -- yours -- is subject to introduction of subtle errors. Use a debugger to check the code (once). Note that even objdump doesn't do segment overrides correctly always.

Keeping these in mind, here are some tips for converting.

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

For a complete description of the differences, get and unzip the files named as.iN (where N is a digit) from the bnuXXXdc.zip archive, then read the chapter ``i386-Dependent'' in the GNU assembler documentation. If you use the stand-alone info reader, type at the DOS prompt:

  info as machine i386
You will see a menu of gas features specific to x86 architecture.


  next     webmaster   donations   bookstore     delorie software   privacy  
  Copyright 1995   by DJ Delorie     Updated Mar 1995