views:

1369

answers:

4

Are assembly language and machine language (for the same underlying system) really the same? Are there any differences between these two concepts?

+5  A: 

Assembly language is a convenience mechanism over the machine language. With assembly language you use mnemonic sequences instead of numeric operation codes and can use symbolic labels instead of manually calculating offsets. It also protects you from really dumb errors - like typing a malformed processor instruction.

Otherwise the assemly language is the equivalent of the machine language. Sometimes you will have an old assembler that will not support mnemonics for some instructions of the newer processors - then you can still insert operation codes directly into the program.

sharptooth
thanks sharptooth,i think i got it
freenight
+1  A: 

In Assembly, instructions are easier-to-understand representations of CPU instructions.

But the assembler also makes, for example, addressing easier:

  • In machine language you have to know the distance (in address space) between where you are and where you want to jump to
  • In Assembly language you call one address "iWantToJumpHere" and then you can say "jump iWantToJumpHere"

This makes assembly much easier to maintain, especially when the distance between the addresses changes.

+2  A: 

Machine language is the "Bit encoding" of a CPU's opcodes.

Assembly langauge is the "Symbolic encoding" of a CPU's opcodes.

So for Example Symbolically:

loop:  dec R1    # Decrement register R1
       bnq loop  # Branch if not equal to zero to
                 # address "loop"

Becomes Bit encoding:

# Mythical CPU Machine code 4 bits operation,
#                           4 bit "option"
       0x41      # 4 is a "dec" and represents r1;
       0x7E      # 7 is bnq and E means PC -2;

Generally it's a one to one relationship, however some assembly languages will ocationally have extra assembly instructions that map to either multiple machine code instructions or reuse another opcode. Such as using machine code "xor R1,R1" as a "clr R1" or something very similar.

In addition assembly languages will tend to support "macro programming" which in the 80's when assembly was used extensively gave the source code a more "high level" appearance. I've personally written assembly macros that looked like "plot x,y" and "Hex Val" to simplify common operations.

For example:

# Mythically CPU Macro
.macro spinSleep x,y
            ld #x,y
localLoop:  dec y
            brq localLoop
.endmacro
# Macro invocation
            spinSleep 100,R1
# Macro expantion
            ld #100,R1
localLoopM: dec R1
            brq localLoopM   # localLoopM is "Mangled" for localization.
NoMoreZealots
A: 

Assemble level language is the first conscious step towards making the programming simple by allowing the programmers to write mnemonics instead of binary code(machine code).

Pranali Desai