Discussion:
GNU as vs nasm?
(too old to reply)
Tyler Eaves
2004-02-16 06:06:21 UTC
Permalink
Hi all,

I'm currently embarking on the journey of learning assembly programming.
It is rather foreign to me, as most of my work has been in higher-level
languages like python, with some C. I'm working through a free book I
found online ("Programming from the Ground Up", available at
https://savannah.nongnu.org/projects/pgubook/). It seems to be
decently written from what I can tell, but it uses GNU as for the
assembler. What reading I've done suggests that A: NASM seriously owns
GNUas for any real programming and B: GNU as and NASM are syntactially
incompatible.

Am I correct in this line of reasoning?

Followups:

1:
If yes, how hard is the switch from GNU as to NASM, and should I
attempt to make the switch as quickly as possible?

2:
Is there any online conversion "cheat sheet" that shows equivilant
constructs in both syntaxes?

3:
Any other suggestions for good, free, beginner level x86 assembly
tutorials/books/etc? (Note: Win32/DOS specific stuff is of little
interest to me as I do not access to such a machine)

3b (Semi-OT):
How about PowerPC assembly? My laptop is a G3-equipped mac, and I've
heard that programming in assembly on RISC architectures like PowerPC
is rather a bit easier than on x86. A bit of quick googling didn't
turn up any good tutorial type information however.

Thanks!
Matt Taylor
2004-02-16 08:46:58 UTC
Permalink
Post by Tyler Eaves
Hi all,
I'm currently embarking on the journey of learning assembly programming.
It is rather foreign to me, as most of my work has been in higher-level
languages like python, with some C. I'm working through a free book I
found online ("Programming from the Ground Up", available at
https://savannah.nongnu.org/projects/pgubook/). It seems to be
decently written from what I can tell, but it uses GNU as for the
assembler. What reading I've done suggests that A: NASM seriously owns
GNUas for any real programming and B: GNU as and NASM are syntactially
incompatible.
Am I correct in this line of reasoning?
Yes. Nasm has a masm-like syntax. GNU as does not. For comparison, here are
two equivalent lines written in each style:

mov eax, [ebx+ecx*4+8] ; nasm
movl 8(%ebx,%ecx,4), %eax ; gas
Post by Tyler Eaves
If yes, how hard is the switch from GNU as to NASM, and should I
attempt to make the switch as quickly as possible?
Gas was designed to be the back-end to gcc. It lacks a lot of features that
are useful for assembly programming. AFAIK it is not possible to create
macros and symbolic constants in gas. Nasm has a fairly powerful
preprocessor. If you have much experience with the C preprocessor, it should
be extremely easy to pick up.

Whether or not you should switch is entirely up to you.
Post by Tyler Eaves
Is there any online conversion "cheat sheet" that shows equivilant
constructs in both syntaxes?
Yes:
http://www.delorie.com/djgpp/doc/brennan/brennan_att_inline_djgpp.html

That page covers inline assembly with gcc, but he also discusses syntactic
differences between Intel syntax and AT&T syntax. It's fairly easy to
convert between the two styles.
Post by Tyler Eaves
Any other suggestions for good, free, beginner level x86 assembly
tutorials/books/etc? (Note: Win32/DOS specific stuff is of little
interest to me as I do not access to such a machine)
I believe it was this website which I always see mentioned:
http://www.linuxassembly.org/
Post by Tyler Eaves
How about PowerPC assembly? My laptop is a G3-equipped mac, and I've
heard that programming in assembly on RISC architectures like PowerPC
is rather a bit easier than on x86. A bit of quick googling didn't
turn up any good tutorial type information however.
Easier? Not really. Whilst x86 is fairly complex, writing x86 code
underneath a modern 32-bit operating system hides most of that complexity.
You may find writing PPC code enlightening, however. Each architecture has
its own clever idioms.

The best place to start is to download PPC manuals and run gcc -S on some
code. Use the manuals to figure out what the individual instructions are
doing, and use the assembly output feature of gcc to figure out things like
calling conventions.

-Matt
Dragon Lord
2004-02-16 09:35:49 UTC
Permalink
Its also good to note

gcc -b <machine type> -S

That will allow you to see the assembly code for a machine type, if you have
a cross platform compiler. I have a few machine types on my linux box even
though its compiled machine type is i386-linux. A fairly standard directory
for looking up machine types, /usr/lib/gcc-lib/, each directory is a
machine type.

Jeremy

----- Original Message -----
From: "Matt Taylor" <***@tampabay.rr.com>
Newsgroups: comp.lang.asm.x86
Sent: Monday, February 16, 2004 3:46 AM
Subject: Re: GNU as vs nasm?
Post by Matt Taylor
Post by Tyler Eaves
Hi all,
I'm currently embarking on the journey of learning assembly programming.
It is rather foreign to me, as most of my work has been in higher-level
languages like python, with some C. I'm working through a free book I
found online ("Programming from the Ground Up", available at
https://savannah.nongnu.org/projects/pgubook/). It seems to be
decently written from what I can tell, but it uses GNU as for the
assembler. What reading I've done suggests that A: NASM seriously owns
GNUas for any real programming and B: GNU as and NASM are syntactially
incompatible.
Am I correct in this line of reasoning?
Yes. Nasm has a masm-like syntax. GNU as does not. For comparison, here are
mov eax, [ebx+ecx*4+8] ; nasm
movl 8(%ebx,%ecx,4), %eax ; gas
Post by Tyler Eaves
If yes, how hard is the switch from GNU as to NASM, and should I
attempt to make the switch as quickly as possible?
Gas was designed to be the back-end to gcc. It lacks a lot of features that
are useful for assembly programming. AFAIK it is not possible to create
macros and symbolic constants in gas. Nasm has a fairly powerful
preprocessor. If you have much experience with the C preprocessor, it should
be extremely easy to pick up.
Whether or not you should switch is entirely up to you.
Post by Tyler Eaves
Is there any online conversion "cheat sheet" that shows equivilant
constructs in both syntaxes?
http://www.delorie.com/djgpp/doc/brennan/brennan_att_inline_djgpp.html
That page covers inline assembly with gcc, but he also discusses syntactic
differences between Intel syntax and AT&T syntax. It's fairly easy to
convert between the two styles.
Post by Tyler Eaves
Any other suggestions for good, free, beginner level x86 assembly
tutorials/books/etc? (Note: Win32/DOS specific stuff is of little
interest to me as I do not access to such a machine)
http://www.linuxassembly.org/
Post by Tyler Eaves
How about PowerPC assembly? My laptop is a G3-equipped mac, and I've
heard that programming in assembly on RISC architectures like PowerPC
is rather a bit easier than on x86. A bit of quick googling didn't
turn up any good tutorial type information however.
Easier? Not really. Whilst x86 is fairly complex, writing x86 code
underneath a modern 32-bit operating system hides most of that complexity.
You may find writing PPC code enlightening, however. Each architecture has
its own clever idioms.
The best place to start is to download PPC manuals and run gcc -S on some
code. Use the manuals to figure out what the individual instructions are
doing, and use the assembly output feature of gcc to figure out things like
calling conventions.
-Matt
SPH
2004-02-16 18:32:30 UTC
Permalink
Post by Dragon Lord
That will allow you to see the assembly code for a machine type, if you have
a cross platform compiler. I have a few machine types on my linux box even
though its compiled machine type is i386-linux. A fairly standard directory
for looking up machine types, /usr/lib/gcc-lib/, each directory is a
machine type.
Do you know of a good tutorial to make a cross platform gcc? Basically,
to do what you have.
Dragon Lord
2004-02-16 20:58:23 UTC
Permalink
I did it all myself, and no i don't have a tutorial to do it. Although to
do all the compiling you need, goto http://gcc.gnu.org/ I started with gcc,
and it has requirements, binutils for one, which is basically gas and a
bunch of others, this also has includes/libs to help make GCC cross
platform.

http://gcc.gnu.org/install/

is a nice installation tutorial

http://gcc.gnu.org/install/specific.html shows you the targets GCC can do
and information about them

also look on any apple sites about compiling GCC on OS X for support of
their processors.

Jeremy
Post by Dragon Lord
Post by Dragon Lord
That will allow you to see the assembly code for a machine type, if you
have
Post by Dragon Lord
a cross platform compiler. I have a few machine types on my linux box
even
Post by Dragon Lord
though its compiled machine type is i386-linux. A fairly standard
directory
Post by Dragon Lord
for looking up machine types, /usr/lib/gcc-lib/, each directory is a
machine type.
Do you know of a good tutorial to make a cross platform gcc? Basically,
to do what you have.
T.M. Sommers
2004-02-17 00:39:15 UTC
Permalink
Post by Matt Taylor
Gas was designed to be the back-end to gcc. It lacks a lot of features that
are useful for assembly programming. AFAIK it is not possible to create
macros and symbolic constants in gas. Nasm has a fairly powerful
preprocessor.
gas's macros are, in the current versions, at least comparable to
NASM's. You can also use the C preprocessor or m4 (which is
the traditional way of doing assembler macros in Unix).
Frank Kotler
2004-02-16 17:12:53 UTC
Permalink
Post by Tyler Eaves
Hi all,
I'm currently embarking on the journey of learning assembly programming.
It is rather foreign to me, as most of my work has been in higher-level
languages like python, with some C. I'm working through a free book I
found online ("Programming from the Ground Up", available at
https://savannah.nongnu.org/projects/pgubook/). It seems to be
decently written from what I can tell, but it uses GNU as for the
assembler. What reading I've done suggests that A: NASM seriously owns
GNUas for any real programming and B: GNU as and NASM are syntactially
incompatible.
Am I correct in this line of reasoning?
"A:" is a matter of opinion (you won't get any argument from me!). "B:"
is definitely correct - although (G)as with the ".intel-syntax noprefix"
option is "less different". Should be noted that Fasm and HLA will also
run on Linux!
Post by Tyler Eaves
If yes, how hard is the switch from GNU as to NASM, and should I
attempt to make the switch as quickly as possible?
"If 'twere done, best 'twere done quickly" - Lady MacBeth
Post by Tyler Eaves
Is there any online conversion "cheat sheet" that shows equivilant
constructs in both syntaxes?
Besides the site Matt mentions - IIRC there's some info about
differences with Intel syntax (not specifically Nasm) in "man as"...
Post by Tyler Eaves
Any other suggestions for good, free, beginner level x86 assembly
tutorials/books/etc? (Note: Win32/DOS specific stuff is of little
interest to me as I do not access to such a machine)
There's a newly-formed "!Yahoo!" list -
http://groups.yahoo.com/group/linux-nasm-users - there are a few
examples, and some good links. Not a *lot* of expertise yet - we're
helping eachother learn. Please join us if you care to!

I've only just taken a quick look at the "pgu" book - looks nice!
Translating examples into Nasm syntax shouldn't be too hard, and might
make an interesting project.

Ignore the indignant squawking from the Penguin! :)

Best,
Frank
Bjarni Juliusson
2004-02-16 19:24:01 UTC
Permalink
Post by Tyler Eaves
I'm currently embarking on the journey of learning assembly programming.
Yay! Welcome :-)
Post by Tyler Eaves
It is rather foreign to me, as most of my work has been in higher-level
languages like python, with some C.
If you understand C, assembly shouldn't be so difficult. I have found it
helps to learn programming from the bottom up though, and have seen
people have trouble learning lower-level programming after having been
introduced to high level languages first.
Post by Tyler Eaves
What reading I've done suggests that A: NASM seriously owns
GNUas for any real programming and B: GNU as and NASM are syntactially
incompatible.
A: Well, NASM is a conventional assembler intended for programming by
humans. GNU as is really a backend and not meant to be particularly
readable or pleasant.

B: GNU as uses AT&T syntax, NASM uses the usual Intel syntax. Some
people like one, some the other, but I for one find the Intel syntax
easier on the human programmer, and *it has the operands the right way
around*!
Post by Tyler Eaves
If yes, how hard is the switch from GNU as to NASM, and should I
attempt to make the switch as quickly as possible?
The switch should be very easy, but you will probably be more
comfortable with Intel syntax and that will be encouraging. Matt said
gas has no macros, and if that's true, NASM is nicer. Since it's easy to
try both and see for yourself, do.
Post by Tyler Eaves
Is there any online conversion "cheat sheet" that shows equivilant
constructs in both syntaxes?
This should be so simple you will not need a cheat sheet.
Post by Tyler Eaves
How about PowerPC assembly? My laptop is a G3-equipped mac, and I've
heard that programming in assembly on RISC architectures like PowerPC
is rather a bit easier than on x86. A bit of quick googling didn't
turn up any good tutorial type information however.
Now I have never programmed a PowerPC, but if it's anything like other
popular RISC processors like the MIPS and SPARC families, it is easier
to program than the x86 family. This is because the instruction set is
very simple and regular. You will spend little time looking through a
one-thousand-page manual for appropriate instructions, and more time
doing actual programming. The x86 family of processors is among the most
difficult processor architectures to program due to its unreasonable
complexity, but that's half the fun!
--
Remove the furry animal from my address to send email:

***@update.ferret.uu.se
T.M. Sommers
2004-02-17 00:39:21 UTC
Permalink
Post by Tyler Eaves
Hi all,
I'm currently embarking on the journey of learning assembly programming.
It is rather foreign to me, as most of my work has been in higher-level
languages like python, with some C. I'm working through a free book I
found online ("Programming from the Ground Up", available at
https://savannah.nongnu.org/projects/pgubook/). It seems to be
decently written from what I can tell, but it uses GNU as for the
assembler. What reading I've done suggests that A: NASM seriously owns
GNUas for any real programming
NASM is popular among those with a DOS or Windows background; gas
is popular among those with a Unix background.
Post by Tyler Eaves
and B: GNU as and NASM are syntactially
incompatible.
gas now has an intel-syntax mode.
Post by Tyler Eaves
Am I correct in this line of reasoning?
If yes, how hard is the switch from GNU as to NASM, and should I
attempt to make the switch as quickly as possible?
It depends on what you want to do. If you want to work on the
kernel, or use gdb or objdump and the like, or if you want to
also work on other flavors of Unix, then you need gas.
Otherwise, either will do. Or better yet, both.
Post by Tyler Eaves
Is there any online conversion "cheat sheet" that shows equivilant
constructs in both syntaxes?
Both are simple enough that such a thing is not really needed.
Post by Tyler Eaves
Any other suggestions for good, free, beginner level x86 assembly
tutorials/books/etc? (Note: Win32/DOS specific stuff is of little
interest to me as I do not access to such a machine)
http://linuxassembly.org

There is also a chapter in the FreeBSD Developers Guide devoted
to assembly, using NASM.

The Intel manuals are available on their web site.

For learning the processor instructions, even a DOS or Windows
book would be useful.
Scott Moore
2004-02-17 06:00:19 UTC
Permalink
Post by Tyler Eaves
Hi all,
I'm currently embarking on the journey of learning assembly programming.
It is rather foreign to me, as most of my work has been in higher-level
languages like python, with some C. I'm working through a free book I
found online ("Programming from the Ground Up", available at
https://savannah.nongnu.org/projects/pgubook/). It seems to be
decently written from what I can tell, but it uses GNU as for the
assembler. What reading I've done suggests that A: NASM seriously owns
GNUas for any real programming and B: GNU as and NASM are syntactially
incompatible.
I recently had a program where I had to do extensive programming using
both. Gas was used because it integrates well with gcc, Nasm was used
to produce bootstrap code that brought an AMD64 processor from 16 bit
real mode all the way to 64 bit page memory mapped mode, which is
what the AMD64 requires.

Along the way, several routines were required to be moved from NASM
to gas, and vice versa, because the two code bases needed the same
routines in places.
Post by Tyler Eaves
Am I correct in this line of reasoning?
If yes, how hard is the switch from GNU as to NASM, and should I
attempt to make the switch as quickly as possible?
Not good. It would be nice to have an automatic translator, but
what can you say ?
Post by Tyler Eaves
Is there any online conversion "cheat sheet" that shows equivilant
constructs in both syntaxes?
I don't have that for you. Basically, the differences are:

1. Gas "assigns" from left to right, that is, "movl %eax,%ebx" moves
eax to ebx. Nasm moves right to left, as in "mov ebx,eax".

2. Gas requires "%" in front of all registers.

3. Gas uses "l", "s", and "w" type postfixes to indicate operator
sizes (long, short, word, just like the "C" language). Nasm uses
Masm like syntax of "mov byte [eax],0".

4. Gas uses "(x)" to indicate indirect contents, nasm uses "[x]".

5. Gas cannot usefully perform 16 bit code. Yes, there are demos
of it being done, but it is unbelieveably painfull. Nasm is great
for multimodal code (code that contains both 16 bit and 32 bit modes),
and so is perfect for bootstraps, which require same.
Post by Tyler Eaves
Any other suggestions for good, free, beginner level x86 assembly
tutorials/books/etc? (Note: Win32/DOS specific stuff is of little
interest to me as I do not access to such a machine).
The online "art of assembly" is pretty good.
Post by Tyler Eaves
How about PowerPC assembly? My laptop is a G3-equipped mac, and I've
heard that programming in assembly on RISC architectures like PowerPC
is rather a bit easier than on x86. A bit of quick googling didn't
turn up any good tutorial type information however.
Is probally going to be a better match for gas than the x86 family.
Post by Tyler Eaves
Thanks!
There have been several negative comments about gas, I think the main
point is that gas is a little less friendly to users who are already
used to the Intel way of doing things due to the gas need to be
a general purpose, multiple processor family assembler. I find gas's
use of "%" for registers and the method of indicating indirection,
and the wild differences between gas and Intel notation to be annoying,
but I will freely admit I have been programming x86 much longer
than gas has been available, so am probally biased.

Both assemblers are a better choice than MASM, which is a horror that
needs to be stamped out of existance. Masm features "typed" addresses
and data, which makes the exact sizing of data and addressing on a
given instruction difficult or impossible to discover without flipping
back and forth in the listing constantly to the data or object
definition to find what "context" the instruction is in. Further,
MASM suffers from a random and meandering design theme that has become
so featurized that it is impossible to understand many programmers
listings without constant reference to the masm manual.

I suffered with Masm for several years. The relief of ceasing its use
was similar to having a goiter removed, no doubt.

Luck !
Dragon Lord
2004-02-17 06:17:22 UTC
Permalink
Post by Scott Moore
Post by Tyler Eaves
Hi all,
I'm currently embarking on the journey of learning assembly programming.
It is rather foreign to me, as most of my work has been in higher-level
languages like python, with some C. I'm working through a free book I
found online ("Programming from the Ground Up", available at
https://savannah.nongnu.org/projects/pgubook/). It seems to be
decently written from what I can tell, but it uses GNU as for the
assembler. What reading I've done suggests that A: NASM seriously owns
GNUas for any real programming and B: GNU as and NASM are syntactially
incompatible.
I recently had a program where I had to do extensive programming using
both. Gas was used because it integrates well with gcc, Nasm was used
to produce bootstrap code that brought an AMD64 processor from 16 bit
real mode all the way to 64 bit page memory mapped mode, which is
what the AMD64 requires.
Along the way, several routines were required to be moved from NASM
to gas, and vice versa, because the two code bases needed the same
routines in places.
Post by Tyler Eaves
Am I correct in this line of reasoning?
If yes, how hard is the switch from GNU as to NASM, and should I
attempt to make the switch as quickly as possible?
Not good. It would be nice to have an automatic translator, but
what can you say ?
Post by Tyler Eaves
Is there any online conversion "cheat sheet" that shows equivilant
constructs in both syntaxes?
1. Gas "assigns" from left to right, that is, "movl %eax,%ebx" moves
eax to ebx. Nasm moves right to left, as in "mov ebx,eax".
2. Gas requires "%" in front of all registers.
3. Gas uses "l", "s", and "w" type postfixes to indicate operator
sizes (long, short, word, just like the "C" language). Nasm uses
Masm like syntax of "mov byte [eax],0".
4. Gas uses "(x)" to indicate indirect contents, nasm uses "[x]".
5. Gas cannot usefully perform 16 bit code. Yes, there are demos
of it being done, but it is unbelieveably painfull. Nasm is great
for multimodal code (code that contains both 16 bit and 32 bit modes),
and so is perfect for bootstraps, which require same.
Post by Tyler Eaves
Any other suggestions for good, free, beginner level x86 assembly
tutorials/books/etc? (Note: Win32/DOS specific stuff is of little
interest to me as I do not access to such a machine).
The online "art of assembly" is pretty good.
Post by Tyler Eaves
How about PowerPC assembly? My laptop is a G3-equipped mac, and I've
heard that programming in assembly on RISC architectures like PowerPC
is rather a bit easier than on x86. A bit of quick googling didn't
turn up any good tutorial type information however.
Is probally going to be a better match for gas than the x86 family.
Post by Tyler Eaves
Thanks!
There have been several negative comments about gas, I think the main
point is that gas is a little less friendly to users who are already
used to the Intel way of doing things due to the gas need to be
a general purpose, multiple processor family assembler. I find gas's
use of "%" for registers and the method of indicating indirection,
and the wild differences between gas and Intel notation to be annoying,
but I will freely admit I have been programming x86 much longer
than gas has been available, so am probally biased.
Both assemblers are a better choice than MASM, which is a horror that
needs to be stamped out of existance. Masm features "typed" addresses
and data, which makes the exact sizing of data and addressing on a
given instruction difficult or impossible to discover without flipping
back and forth in the listing constantly to the data or object
definition to find what "context" the instruction is in. Further,
MASM suffers from a random and meandering design theme that has become
so featurized that it is impossible to understand many programmers
listings without constant reference to the masm manual.
I suffered with Masm for several years. The relief of ceasing its use
was similar to having a goiter removed, no doubt.
Personal Experience? hehehe ;-)

jeremy
Post by Scott Moore
Luck !
Grumble
2004-02-17 19:13:53 UTC
Permalink
Post by Scott Moore
There have been several negative comments about gas, I think the
main point is that gas is a little less friendly to users who are
already used to the Intel way of doing things due to the gas need
to be a general purpose, multiple processor family assembler. I
find gas's use of "%" for registers and the method of indicating
indirection, and the wild differences between gas and Intel
notation to be annoying, but I will freely admit I have been
programming x86 much longer than gas has been available, so am
probally biased.
You made me curious :-)

As far as I can tell, work on the GNU assembler started in 1986,
possibly 1985, a few months after Richard Stallman founded the Free
Software Foundation.

http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/read.h?rev=1.1&cvsroot=src
Scott Moore
2004-02-17 19:52:37 UTC
Permalink
Post by Grumble
Post by Scott Moore
There have been several negative comments about gas, I think the
main point is that gas is a little less friendly to users who are
already used to the Intel way of doing things due to the gas need
to be a general purpose, multiple processor family assembler. I
find gas's use of "%" for registers and the method of indicating
indirection, and the wild differences between gas and Intel
notation to be annoying, but I will freely admit I have been
programming x86 much longer than gas has been available, so am
probally biased.
You made me curious :-)
As far as I can tell, work on the GNU assembler started in 1986,
possibly 1985, a few months after Richard Stallman founded the Free
Software Foundation.
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/read.h?rev=1.1&cvsroot=src
The 8086 was introduced in 1978. See

http://www.ox.compsoc.net/~swhite/history/8086.html

So 8 years more. The 8086 is 4 years older than the PC. I'm a lot older
than both :-)
Tim Roberts
2004-02-19 05:16:41 UTC
Permalink
Post by Grumble
... but I will freely admit I have been
programming x86 much longer than gas has been available, so am
probally biased.
You made me curious :-)
As far as I can tell, work on the GNU assembler started in 1986,
possibly 1985, a few months after Richard Stallman founded the Free
Software Foundation.
Yes, but...

The so-called "gas syntax", which is really the issue here, is derived
directly from the AT&T Unix assemblers, and that dates back to the
early-to-mid 1970s.
--
- Tim Roberts, ***@probo.com
Providenza & Boekelheide, Inc.
T.M. Sommers
2004-02-20 11:24:50 UTC
Permalink
Post by Tim Roberts
Post by Grumble
As far as I can tell, work on the GNU assembler started in 1986,
possibly 1985, a few months after Richard Stallman founded the Free
Software Foundation.
Yes, but...
The so-called "gas syntax", which is really the issue here, is derived
directly from the AT&T Unix assemblers, and that dates back to the
early-to-mid 1970s.
And the original Unix PDP-11 assembler derived its syntax from
the DEC PAL-11R assembler. See
http://wolfram.schneider.org/bsd/7thEdManVol2/assembler/assembler.html
Continue reading on narkive:
Loading...