(Answer) (Category) SCO comp.unix.sco.programmer FAQ. : (Category) SCO Development Environments. :
Assembler overview; differences of "AT&T" vs. "Intel" syntax
There is no doc that I know of that describes the assembler syntax used
by the assemblers in the modern UNIX products.  Mostly, it's understood
via a combination of studying what the native compiler emits and UNIX
"folklore" about how UNIX assemblers have always worked.  The (sad)
state of affairs is that people that should be writing assembler code
just seem to be able to figure these things out.  No, I won't pretend
that's a good answer or one that we should be proud of.  Darwinism
shouldn't be justification for doc failures.

You can learn a lot about the assembler syntax by watching how the 
compiler writes assemblers.   Start with a tiny program:

        int x;
        main()
        {
                x = 0x1234;
        }

Compile it with -S and then look at the resulting .s file.  This will
show you how to make symbols global, how to separate text and data,
how to represent constants, and those three of four other "gotta know"
things.


Now, to complete the earlier setup, we'll visit history.  

When Intel or any other CPU vendor releases a family of processors,
they almost always have an assembler written for it.  The syntax for
that assembler is used the examples in their databooks and is therefore
a very handy thing to be able to read and possibly write.  Now the
Intel assembler syntax for IA32 (nee x86) isn't a very pretty thing,
but it was definitely the first kid on this block.  This is known as
"Intel assembler syntax" and is the syntax used by most X86 assemblers
including MASM last time I looked.

In the mid '80's AT&T decided to flirt with porting UNIX to those
286 and 386 thingies, but decided to contract out some of the work.
Assemblers are pretty boring, so that work went to either Microport
or Interactive Systems Corp as legend has it.  (These were the days
when both these companies were known as porting houses and not as
shrink-wrapped UNIX vendors.)  They saw the Intel syntax and gagged.  So
they created their own assembler that was similar to some existing UNIX
assembler - perhaps it was as much to simplify their port as it was out
of "purity" of the language.  This became known as "AT&T/386 assembler
syntax" and is the syntax used by all the UNIX assemblers for x86 that I
know of including the GNU assembler.

Other than being completely different, they're quite similar.  To move
'1' into 32 bit memory address x, one would use:

        movl $1, x              / AT&T syntax - move long, immed 1 -> x
                                / "word" = 16 bits, "long" = 32.
or
        move dword ptr x, $1    / Intel syntx.  dbl word ptnr x <- immed 1
                                / "word" = 16 bits, so "dword" = 32.


In AT&T syntax, the name of the opcode (movb, movw, movl) signfies
the width of the operands.  In Intel syntax, it's the funky qualifier
thingies in the middle that achieves the same.  There's also the minor
difference that the direction is backwards between the two.   

So, if you find an Intel book on assembler syntax  it will do you some
good for an AT&T-based assembler but you have to read it in a mirror and
remember to always do conversions on every line you read.
robertlipe@usa.net
[Append to This Answer]
Previous: (Answer) I am having trouble building and running an application with gcc, but someone else is not.
Next: (Answer) What popular compilers are available?
This document is: http://www.zenez.com/cgi-bin/scoprogfaq/faq?file=89
[Search] [Appearance]
This is a Faq-O-Matic 2.721.