Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is assembly language `assembler` specific too? Which assembler is best?

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"

like image 953
claws Avatar asked Jan 03 '10 16:01

claws


2 Answers

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..

like image 134
Richard Pennington Avatar answered Sep 21 '22 02:09

Richard Pennington


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.

like image 39
DigitalRoss Avatar answered Sep 23 '22 02:09

DigitalRoss