From: Rod Pemberton on

"Brian" <stringchopperREMOVEALLCAPS(a)REMOVEALLCAPSgmail.com> wrote in message
news:rj0at2lqgdbhgp8k6u0u7t722cqfpsh9ig(a)4ax.com...
> I'm about half-way through Jeff Duntemann's, "Assembly Language Step
> by Step". (excellent foundational book so far IMO, if a bit dated -
> still works though!)
>

I can't recommend any books. I knew 6502 assembly and learned basic x86
from code snippets, the Intel CPU manuals, and other online instruction set
references:
http://www.ews.uiuc.edu/~cjiang/reference/About_IA-32_Instructions.htm
http://www.gamedev.net/reference/articles/article214.asp

> Jeff's book uses NASM with the ultimate goal of moving to Linux for
> protected mode assembly. What are the various opinions of you who
> read and post to alt.lang.asm? Do you prefer NASM, MASM or some other
> assembler? Do you work mostly on a Unix like machine or Windows? Does
> it matter?
>

I prefer NASM and GAS. I like NASM for it's clean syntax and I like GCC's
inline assembly (GAS) because it has a very powerful method of interfacing
assembly with C. My C code is mostly written for DJGPP (GCC based) and
OpenWatcom under DOS occasionally using inline assembly (GAS,WASM). I also
write small helper programs for DOS using NASM.

> I may go through Wrox's "Professional Assembly Programming" next, but
> it uses GAS, and I'm not sure if 'non-intel' syntax will mess me up,
> as I'm beginning. Should a beginner go straight to MASM (and a
> tutorial that uses MASM) you think?
>

I knew 6502 assembly (and had very minor 68000 exposure), so I found
learning x86 using simple NASM's syntax to be quite easy. But, even NASM's
mostly clean syntax has some oddities: for a far jmp it's "jmp far", not
"jmpf," but for a far return it's "retf", not "ret far". You can use it's
"%if" macro to test multiple arguments, but not it's other "%if" macro's
like "%ifidn". Although the NASM documentation appears well written and
complete, there are many things that are just missing or not covered, like
how to use certain keywords or features or what they mean. I suspect most
of the lacking stuff was "common knowledge" to the key developers from the
other assemblers they worked with. You'll occasionally will need to consult
Intel or MASM documents to get answers.

The first part of picking up GAS is that the arguments are reversed from the
Intel documentation for most, but not all, instructions. The second part is
that most instructions require a size letter added to the instruction: i.e.,
it's not "mov" but "movw" or "movl". The third part is just extra typing:
"syntactic decoration". The fourth problem is the "%" or "%%". If you
don't have any branches in the assembly, you use one percent to reference
arguments, but if you have branches, one percent is used for the branches
and two are used to reference arguments. I had a bunch of good GAS links
added to the alt.os.development FAQ (just started).

The problem I have with MASM is that it requires keywords in places where I
wouldn't normally consider putting them for assembly or a high level
language like C and in many places where it's completely unnecessary. So,
I've never quite gotten used to this.


Rod Pemberton


From: santosh on
Brian wrote:
> I'm about half-way through Jeff Duntemann's, "Assembly Language Step
> by Step". (excellent foundational book so far IMO, if a bit dated -
> still works though!)

It's good as far as it goes.

> Jeff's book uses NASM with the ultimate goal of moving to Linux for
> protected mode assembly. What are the various opinions of you who
> read and post to alt.lang.asm? Do you prefer NASM, MASM or some other
> assembler? Do you work mostly on a Unix like machine or Windows? Does
> it matter?

Other people's opinions don't matter. What matters is what you want to
do. Do you intend to continue programming in assembler or do you
intend to move on to an HLL? Do you have a preference for a particular
OS or do you want to as OS transparent as possible? Do you prefer to
program as much as possible yourself or do you like calling prebuilt
routines whenever possible. Do you like minimal low-level assembly or
are you attracted more towards macro and high-level-language
statements rich assembly? Do you need comprehensive documentation or
you can make do with sparse docs and resources on the Net?

> I may go through Wrox's "Professional Assembly Programming" next, but
> it uses GAS, and I'm not sure if 'non-intel' syntax will mess me up,
> as I'm beginning.

No it won't mess you up. It's only slightly different from the so-
called Intel syntax. Do you get "messed up" if you learn Java after C+
+? If not, then why should you in this case?

> Should a beginner go straight to MASM (and a
> tutorial that uses MASM) you think?

It's all your choice. Be aware that MASM will only work under Windows.
If you want to program for and under more than just Windows, MASM is
not the way to go. FASM, (http://flatassembler.net/) works under
Windows/DOS, Linux and other systems. It's closer syntactically to
NASM than other assemblers. RosAsm (http://rosasm.org/), gives you a
easy-to-use Integrated Development Environment (IDE), but, again, it
is Windows specific and forbids creating object modules. GoAsm,
(search with Google, I don't remember the link), also gives a suite of
tools in one integrated package, but, it too is Windows specific and
closed source. GAS, (GNU version of as), is available nearly
everywhere under the Sun, so if you want to learn one syntax and use
it as far as possible, it might interest you. It's usually supplied
along with most UNIX and Linux systems. Under Windows and DOS, it
available as a part of MinGW and DJGPP respectively. It's slightly
harder to use, initially, than some of the other assemblers, since it
was mainly meant as a back-end assembler for the C compiler.

> I use Windows mostly if that matters.

Most UNIX tools, like GAS, run under Windows, but the reverse is not
often true. Your choices, among many others are, NASM, FASM, GAS,
RosAsm, GoAsm, YASM, MASM, TASM and HLA. YASM is a clone of NASM while
TASM is a nearly obsolete clone of MASM. HLA is a "high level
assembler", which claims to make learning assembler easy, but YMMV.

> Any suggestions for a *modern* "learn by example" assembly book (in
> the pentium 3 to 4 range)?

Once you learn the basics of memory addressing and instruction usage,
picking up the details of the newer CPUs and the API of the various
OSes is not difficult, though it is tedious.

From: santosh on

Brian wrote:
> On 15 Feb 2007 19:05:20 -0800, "Evenbit" <nbaker2328(a)charter.net>
> wrote:
> >On Feb 15, 8:13 pm, Brian
> ><stringchopperREMOVEALLC...(a)REMOVEALLCAPSgmail.com> wrote:

<snip>

> >There is a potential to learn more if one is platform-agnostic. The
> >CPU doesn't know what a OS is.
> >
> so a DOS interrupt works on linux too?

If you run your program under DOSEmu, then yes.

<snip>

> >> as I'm beginning. Should a beginner go straight to MASM (and a
> >> tutorial that uses MASM) you think?
> >
> >Does MASM appeal to you?
>
> too early in my studies to tell. I'm so new to assembly that I would
> like direction in ways to *not* waste time learning. I was hoping
> more for input as to the potential hazards in the learning cycle. ie,
> should I learn AT&T syntax to work with gas, or is that a waste of
> time. I realize that will often come down to personal preference, but
> ironically, I'm too new to have a personal preference.

If you'll be programming under a UNIX system and for some reason NASM
is unavailable or is out of question, then as will be your only
choice. AT&T syntax and as existed much before Intel and it's syntax.
It is still the assembler of choice for UNIXish system programming
like the Linux kernel. If you want to inspect the assembler output of
C and C++ compilers under UNIX, then you'll need to know the AT&T
syntax. If you fit any of these criteria, then do consider learning
the use of gas. It doesn't neccessarily have to be your first
assembler. You can take your first steps with NASM or some other Intel
syntax assembler and move on to GAS later. One book which teaches
Linux assembly programming with GAS as a first language is
"Programming From Ground-Up" by Jonathan Bartlett. It's freely
available on the Net, use Google.

> >> I use Windows mostly if that matters.
> >
> >Perhaps it matters to you...
>
> hence the pronoun "I" followed up redundantly with "you".
>
> >> Any suggestions for a *modern* "learn by example" assembly book (in
> >> the pentium 3 to 4 range)?
> >
> >Source code from 'a book' can only take you so far. Finding source
> >code from the 'net can be helpful. But 'experience' is the best
> >teacher -- so write your *own* source code.
>
> I'm really not that far yet, and prefer some more ground-work
> foundational instruction - something as a base that I can tinker with

Also consider Dr. Paul Carter's book "PC Assembly Language". It uses
NASM and it's applicable for both Windows and Linux; http://
www.drpaulcarter.com/pcasm/

The acclaimed "Art of Assembly" by Randall Hyde is also reputed to
make learning assembler easy. It too is freely available. It uses the
"high level assembler" or HLA as it's tool of choice. Many people have
strong opinions regarding HLA.

Other assemblers like RosAsm, FASM and GoAsm come bundled with their
own documentation and demos. It's rather sparse in the case of FASM.

Masm32 is the first choice for using MASM under Windows. http://
www.masm32.com/

In summary both RosAsm and HLA claim to offer rapid and easy way to
learn assembly. Both are rather acquired tastes. They may work
fantastically or they may end up wasting your time. It's for you to
take the gamble. Both have lots of documentation and samples. RosAsm
is an IDE while for HLA there's HIDE and RadASM, (use Google to search
for these). Both offer pseudo-HLL constructs, though the HLL tilt of
HLA is far more than RosAsm, (as you probably can guess by it's name).

Of the remaining, AFAICT, books are available only for NASM, MASM,
TASM, and GAS. Of these TASM is nearly obsolete. You need to buy the
very costly Borland Development Environment to use it. Example code is
widely available for MASM and NASM and less so for TASM and GAS. MASM
integrates well with Microsoft's Visual C++, while NASM and GAS are
very portable and general purpose. RadASM can be made to work with all
of these. Additionally for NASM there's NaGoa and AsmIDE.

>From the machine code point of view, FASM and MASM are the most
uptodate. They both support uptil SSE3 and have 64-bit support.

The choice depends on how you prefer to learn. Whether you prefer a
good book or you can make do with bits and samples. Whether you *must
have* a graphical IDE or not. Whether you prefer advanced HLL-like
constructs and library routines or a more bare-bones syntax. Whether
you intend to program under multiple OSes or not.

From: santosh on
Jim Carlock wrote:
> "Brian" posted...
> : I'm about half-way through Jeff Duntemann's, "Assembly Language
> : Step by Step". (excellent foundational book so far IMO, if a
> : bit dated - still works though!)
> :
> : Jeff's book uses NASM with the ultimate goal of moving to Linux
> : for protected mode assembly. What are the various opinions of
> : you who read and post to alt.lang.asm? Do you prefer NASM,
> : MASM or some other assembler? Do you work mostly on a
> : Unix like machine or Windows? Does it matter?

<snip>

> Microsoft seems to be offering the Kernel Mode Driver Framework
> once again. It's currently marked as Version 1.5 and ends up as a
> 2.4 GB iso image to download.
>
> They offer a smaller DDK package as well. Both provide versions
> of the MASM compilers, but you have to agree to Microsoft's terms
> of use. It's currently dated January 30, 2007.
>
> http://www.microsoft.com/whdc/DevTools/WDK/WDKpkg.mspx

Do you consider the KMDF and/or DDK to be suitable recommendations for
a newbie? What's wrong with the MASM version in masm32?

From: Evenbit on
On Feb 16, 10:13 am, Brian
<stringchopperREMOVEALLC...(a)REMOVEALLCAPSgmail.com> wrote:
> >There is a potential to learn more if one is platform-agnostic. The
> >CPU doesn't know what a OS is.
>
> so a DOS interrupt works on linux too?

No. But an 'interrupt' is a feature of the CPU -- not a feature of
the OS. The OS simply supplies the code that should be executed when
the interrupt occurs. The sequence of "assembly language
instructions" that a programmer uses for his application remains
basically the same when moving trans-platform. It is the criteria,
parameters... "the devil is in the details"... that change. For
example:

DOS exit:
MOV AH, 4Ch
INT 21h

Linux exit:
MOV EAX, 1
MOV EBX, 0
INT 0x80

> >Source code from 'a book' can only take you so far. Finding source
> >code from the 'net can be helpful. But 'experience' is the best
> >teacher -- so write your *own* source code.
>
> I'm really not that far yet, and prefer some more ground-work
> foundational instruction - something as a base that I can tinker with

Lots of "foundational" stuff here:
http://webster.cs.ucr.edu/AoA/Windows/index.html

Nathan.