News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Answer some basic & personal questions! :)

Started by dottywine, November 20, 2008, 06:54:11 PM

Previous topic - Next topic

dottywine

Hi, can you guys help me to understand something.

In my class, we use a book by a man named Irvine. I also read something about Intel processors and 32 bit such and such...

Does this mean that every type of processor has its OWN assembler language?

Is assembler not like java or C++ where everything is the same?

What is the most popular form of assembler?

Those of you learning assembler, why are you doing so? What will you use it for?

donkey

QuoteDoes this mean that every type of processor has its OWN assembler language?
Every family of microprocessors has it's own unique assembly language, and within that family each generation generally has extensions to the language added. For example the Pentium CPU instruction set is generally binary compatible right back to the 8086 8 bit CPU and the 80286 32 bit CPU. Other examples of microprocessor families are the Motorola 68K, SPARC, 65xx etc...

QuoteIs assembler not like java or C++ where everything is the same?
No assembler is completely unique to each microprocessor as well as each OS

QuoteWhat is the most popular form of assembler?
For the x86 family under Windows the de-facto standard is MASM.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Mark Jones

Quote from: dottywine on November 20, 2008, 06:54:11 PM
What is the most popular form of assembler?

Just a note, C++ and Java are High-Level-Languages, meaning that their source code is created in such a way as to generalize, unify, and simplify the act of programming. (All arguable.)  However, as the C++ and Java compilers crunch source code into binary, the code still must pass through something resembling an "assembler" stage. They do this quite differently, but both achieve the same result of binary data which is formatted properly to be executable by the target operating system/processor family. Normally for us, this target is Windows 2k/XP/NT and above, using the x86 family of processor. But there are often compiler settings for specifiying different OS and processor targets (Windows CE for example.)

Programming "in assembly" avoids all of this upper-level "stuff" and thus everything is done manually, by hand... which can be advantageous.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

MoreBits

Quote from: dottywine on November 20, 2008, 06:54:11 PM
Does this mean that every type of processor has its OWN assembler language?
...
Is assembler not like java or C++ where everything is the same?

Hi,

answer depends a bit on the viewpoint:

Every processor type has his own machine code - binary data as e.g. "0001 1100 0111 1101", which, if given as electric signals (LOW/HIGH) to the appropriate contacts on the processor core, will drive the processor to do something hopefully useful...
There are "processor families", as e. g.  x86, with a common machine code set and unique extensions depending on the special type. The common code set is necessary for compatibility.

Now we step to  assembler:
Because it is to complicated for most human beings to memorize all the binary codes and to put the necessary codes into the right sequence for the processor, a tool was invented to do that work. That tool is given a kind of more human readable source code, consisting of so called "mnemonics". Mnemonics are abbreviations of instructions as e. g. "MOV" for "move something from ... to...". Mostly, the source consisting of mnemonics ( and some  more) is called "assembler code" and the tool able to make a binary code for the processor from that code is called "assembler". The tool for the opposite way is a "Disassembler"....

(To have a better understanding, think about the time computers were programmed by punched cards. It was a big step forward for a programmer to have a machine to make that cards using  the programmers code and not to do that work himself.)

Ideally, there could be an assembler code identical for all types of processors. In reality, that won't happen, e. g. due to too different processors and instruction sets. Even if that would exist, the "overall" assembler itself has to be able to generate special code for every processor or it would be necessary to have different assemblers for every different processor. The last mentioned way is the todays "normal" way and used also with languages like C++ during the steps from source to machine binary code.

So far, but some points more:
As always, it wasn't invented one tool and one set of mnemonics... Today, we have at least two important schools how to write assembler code with different mnemonics and syntax rules, the MASM syntax and the AT&T syntax. There are some other and derivatives, but that's not important for now. The different kind of writing the source code causes different assembler programs - but they result within (nearly) identical binary code if the same program for the same processor was written and assembled.

So your questions are to answer as follows:
Every processor has is own (binary) instruction set with subsets identical to other processors of the same family.
Assembler source code consist of mnemonics for that binary instruction code. There are different syntaxes how to write such code. Theoretically,  assembler source code could be standardized like C++ or Java or ...
Assembler programs use source code of a special syntax to generate binary code for a special processor or a processor family.

regards

MoreBits

Mirno

As Donkey says, each instruction set has it's own assembly language.
You need to understand where assembly language came from to understand why it's the way it is. Historically computers were programmed in machine code, everything was a number, and all entered by hand. This was error prone (did you mean 0x1234 or 0x1243?), so assemblers came in as the simplest mapping between machine code and human readable code.
Each processor has it's one specific instruction encodings (00 01 could be add on one processor, where as 01 could be add on another, or 02, or...), you can have fixed width instructions (all instructions are 16 bit (plus more bytes for memory arguments)), or variable width etc.
The assembler will deal with all of this, and when you type "add eax, ecx", the assembler sees "add <reg>, <reg>, with register 0 for argument 1, and register 2 for argument 2", it then encodes this appropriately.

Other features, such as labling, procedures, and high level syntax came later as the processors became more powerful, and assembler became much more of a language (rather than a glorified search and replace procedure!). But it's origin remains that of (virtually) the simplest human readable language you can create.

As the assembler is tied to a specific instruction set, this sets it apart from the likes of C. Interestingly Java runs on it's own virtual machine, so all versions of Java do compile for the same "processor", although it is a virtual one whose standards are/were defined by Sun Microsystems.
Assembler is not portable in the same way that C is (or at least can be if written properly).

In terms of the most programmed assembler, you will most likely find it's either ARM, or Z80. Both are heavily used in embeded devices (Z80 is washing machines and such appliances, and ARM in mobile phones, some appliances which have more advanced features, and hand held games consoles (the Nintendo DS uses an ARM7 core, and an ARM9)). There will also be a fair amount of programming in assembler for Cell processor, and PowerPC, as they are used in the PS3, and XBox360 respectively.

Why you learn assembler is up to you - the number of jobs which use it exclusively are relatively few, but games developers do, BIOS engineers do, and embedded programmers do use it quite a lot. Also anyone who has to do serious debugging, knowing assembler is a good thing to know.
Anyone who wants to program in any serious capacity should at least learn how assembler works, and why it works the way it does. Because it is "human readable machine code", it helps you understand why certain tricks work in other languages. It gives a much better understanding of the machine, and so informs you as to how to write other code (and more importantly, how not to write code).

Mirno