What's the relationship between assembly language and machine language?

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


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.

I found a really good explanation, thought to post it here, so that others could read it:

Machine language is the actual bits used to control the processor in the computer, usually viewed as a sequence of hexadecimal numbers (typically bytes). The processor reads these bits in from program memory, and the bits represent "instructions" as to what to do next. Thus machine language provides a way of entering instructions into a computer (whether through switches, punched tape, or a binary file).

Assembly language is a more human readable view of machine language. Instead of representing the machine language as numbers, the instructions and registers are given names (typically abbreviated words, or mnemonics, eg ld means "load"). Unlike a high level language, assembler is very close to the machine language. The main abstractions (apart from the mnemonics) are the use of labels instead of fixed memory addresses, and comments.

An assembly language program (ie a text file) is translated to machine language by an assembler. A disassembler performs the reverse function (although the comments and the names of labels will have been discarded in the assembler process).

Source : What is difference between machine language and assembly language?