5
votes

I'm learning assembly language. I started with Paul A. Carter's PC Assembly Language which uses NASM (The Netwide Assembler). Then in the middle I switched and started reading Introduction to 80×86 Assembly Language and Computer Architecture which uses MASM.

In NASM I used to write, for initializing a byte

db 110101b

In MASM I'm using

BYTE 110101b

I'm in the middle of reading. Since these are Assembler directives they will be different for each assembler. right? Doesn't these assembler developers follow a standard for these directives? Because, They know that mnemonics are CPU specific. So, its pain in the ass to learn and code in assembly language.

Now if they follow different directives, its more pain if you change assembler or if you switch the operating system (MASM developer is in deep trouble if he goes to linux).

My confusion is should I acquaint myself with NASM or MASM? I'm fan of windows but I may have to work (in future) on Linux also.

Every book should be titled "_________ Assembly Language using __________ Assembler"

4
Out of curiosity, what will you use Assembler language for? Are you planning on working for a hardware manufacturer, or learning it for broader education purposes? (I know little about Assembler language and its related careers)orokusaki
Yeah, I'm an electronics guy & have plans for joining an hardware manufacturer company. I'm also an highlevel programmer who wants to understand how things are working. So, it helps me both ways :)claws
@claws: Given your comment and background, you might want to look at the GNU assembler. I suspect you'll be dealing with more than x86 processors as time goes on... I use the GNU assembler for ARM, MIPS, Nios2, Sparc, x86 and others.Richard Pennington
Thank you, Richard. I'll surely acquaint myself with GAS but the books I've either uses NASM or MASM. So, I need to stick with either of these atleast till I finish learning. If you know any book that follows GAS. Please suggest.claws
There are some resource links at grc.com/smgassembly.htmTrueWill

4 Answers

4
votes

Unfortunately there has never been a standard for assembly language. You'll just have to learn the directives that your assembler supports. Fortunately most of the directives, while having different names, are semantically similar like db and BYTE.

But wait! It gets worse, especially for the x86. You have (at least) two forms of code that assemblers can accept: Intel and AT&T format. AT&T format reverses the order of most operands to instructions (or is it visa versa ;-).

NASM is probably a better choice for portability, but you could also look at the GNU assembler..

2
votes

Intel Syntax / AT&T Syntax

With x86 in particular, the first assemblers were from Intel and then largely-compatible assemblers from Microsoft formed one branch.

These assemblers organize source and destination operands right to left and have an unusual (and to my eyes, kind of wacky) abstraction layer that uses a single mnemonic for 8, 16, and 32-bit ops and then derives the actual machine opcode to use based on properties of the operand. Modifiers exist (on operands) to force a particular size.

But Unix was also important and it had a completely different assembler line with different traditions and conventions.

The original Unix vendor was AT&T, which owned the intellectual property developed at Bell Labs. A series of BSD projects and then Linux continued with this tradition. These assemblers historically process operands left to right, have a spare design optimized for speed, and when used by humans they generally use cpp for macros and conditionals, even if the assembler also has parallel features.

These days you are probably using VS on MS or Gnu on Linux or Mac, but this is why we still say AT&T vs Intel. The GNU assembler has an option to assemble both ways, although it's still really in the AT&T camp.

1
votes

Generally yes. They are mostly feature-compatible though, so converting from one assembler syntax to another is usually not terribly difficult if you know both.

1
votes

Processors are all documented in a manufacturer supplied Reference manual. This usually developed into the normative syntax (along with the assembler provided by the vendor) for assembly programs on a particular platform. Consequently, many processors from a single vendor have similar syntax.

The situation became more complex with second sourcing of processors and the eventual development of multi-targeting assemblers that, for historical reasons, use mostly consistent syntax across all platforms. This also provides some arguable advantages when porting code across platforms.

Your best choices are to: pick a notation you are comfortable with and accept books with different syntax, see if you can locate cross-system macro libraries or translation tools or bite the bullet and learn multiple dialects. The third is usually tolerable although it makes building private libraries labour intensive.