delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/05/27/18:47:43

From: "Andrew Crabtree" <andrewc AT rosemail DOT rose DOT hp DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Inline ASM: movsx?
Date: Wed, 27 May 1998 13:59:37 -0700
Organization: Hewlett-Packard, Roseville
Lines: 111
Message-ID: <6khure$orl$1@rosenews.rose.hp.com>
References: <aTLa1.196$iY6 DOT 841039 AT news DOT itd DOT umich DOT edu>
NNTP-Posting-Host: ros51675cra.rose.hp.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Krian U wrote in message ...
>>Instructions like movsx and movcx give an "unrecognized 386 instruction"
Perhaps you forgot the size suffix?  Or perhaps you are trying to program
with intel style assembly, instead of at&t?  Check the FAQ for pointers to
assembly stuff.

> I can't seem to find much info on GCC inline asm in the FAQ
>or around the web.

Are you sure you looked?  Relevant info cpoied from the FAQ and pasted at
the bottom of message.

>but I was wondering if
>there is a way to access local variables in inline asm, without having to
pass
>them in as arguments, or fiddling around with the bp.
You could have shadow global variables and assign them to globals, but its
easiest to just pass then in and reference with gcc inline asm style.

Andy

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 "AT&T"
syntax, which is different from "Intel" syntax.  Notable differences between
the two syntaxes are:

   * AT&T immediate operands are preceded by `$'; Intel immediate operands
     are undelimited (Intel `push 4' is AT&T `pushl $4').

   * AT&T register operands are preceded by `%'; Intel register operands are
     undelimited.  AT&T absolute (as opposed to PC-relative) `jump'/`call'
     operands are prefixed by `*'; they are undelimited in Intel syntax.

   * AT&T and Intel syntax use the opposite order for source and destination
     operands.  Intel `add eax, 4' is `addl $4, %eax' in AT&T syntax.

     The `source, dest' convention is maintained for compatibility with
     previous Unix assemblers, so that GCC won't care about the assembler
with
     which it is configured, as some of GCC installations (on systems other
     than MS-DOS) don't use GNU Binutils.

   * In AT&T syntax, the size of memory operands is determined from the last
     character of the opcode name.  Opcode suffixes of `b', `w', and `l'
     specify byte (8-bit), word (16-bit), and long (32-bit) memory
     references.  Intel syntax accomplishes this by prefixing memory
operands
     (*not* the opcodes themselves) with ``byte ptr'', ``word ptr'', and
     ``dword ptr'.'  Thus, Intel `mov al, byte ptr FOO' is `movb FOO, %al'
in
     AT&T syntax.

   * Immediate form long jumps and calls are `lcall/ljmp $SECTION, $OFFSET'
     in AT&T syntax; the Intel syntax is `call/jmp far SECTION:OFFSET.'
     Also, the far return instruction is `lret $STACK-ADJUST' in AT&T
syntax;
     Intel syntax is `ret far STACK-ADJUST.'

   * The AT&T assembler does not provide support for multiple-section (aka
     multi-segment) programs.  Unix style systems expect all programs to be
     single-section.

   * An Intel syntax indirect memory reference of the form

           SECTION:[BASE + INDEX*SCALE + DISP]

     is translated into the AT&T syntax

           SECTION:DISP(BASE, INDEX, SCALE)

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, get and unzip the files named
`as.iN' (where `N' is a digit) from the bnu27b.zip, e.g.
ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/bnu27b.zip archive, then
see See i386-dependent features in "GNU assembler documentation", or point
your Web browser to http://www.delorie.com/gnu/docs/gas/as_190.html#SEC192.
If you don't read this FAQ with an Info browser, type at the DOS prompt:

      info as machine i386

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

A guide is available which was written by Brennan Mr. Wacko Underwood
<brennan AT mack DOT rt66 DOT com>; 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, at this URL:

     http://www.rt66.com/~brennan/djgpp/djgpp_asm.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, e.g.
ftp://ftp.simtel.net/pub/simtelnet/msdos/asmutl/nasm091.zip, which is a free
portable assembler.  It is compatible with DJGPP and accepts a syntax which
is almost 100% compatible with the Intel style.




- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019