Assembly Language Programming
Assembly Language Programming
Basic concept
A Hierarchy of Languages
Assembly and Machine Language
• Machine language
– Native to a processor: executed directly by hardware
– Instructions consist of binary code: 1s and 0s
• Assembly language
– Slightly higher-level language
– Readability of instructions is better than machine language
– One-to-one correspondence with machine language instructions
• Assemblers translate assembly to machine code
• Compilers translate high-level programs to machine code
– Either directly, or
– Indirectly via an assembler
Compiler and Assembler
Instructions and Machine Language
• Each command of a program is called an
instruction (it instructs the computer what to
do).
• Computers only deal with binary data, hence
the instructions must be in binary format (0s
and 1s) .
• The set of all instructions (in binary form)
makes up the computer's machine language.
This is also referred to as the instruction set.
Instruction Fields
• Machine language instructions usually are made up of
several fields. Each field specifies different information
for the computer. The major two fields are:
• Opcode field which stands for operation code and it
specifies the particular operation that is to be
performed.
– Each operation has its unique opcode.
• Operands fields which specify where to get the source
and destination operands for the operation specified by
the opcode.
– The source/destination of operands can be a constant, the
memory or one of the general-purpose registers.
Assembly vs. Machine Code
Instruction Address Machine Code Assembly Instruction
0005 B8 0001 MOV AX, 1
0008 B8 0002 MOV AX, 2
000B B8 0003 MOV AX, 3
000E B8 0004 MOV AX, 4
0011 BB 0001 MOV BX, 1
0014 B9 0001 MOV CX, 1
0017 BA 0001 MOV DX, 1
001A 8B C3 MOV AX, BX
001C 8B C1 MOV AX, CX
001E 8B C2 MOV AX, DX
0020 83 C0 01 ADD AX, 1
0023 83 C0 02 ADD AX, 2
0026 03 C3 ADD AX, BX
0028 03 C1 ADD AX, CX
002A 03 06 0000 ADD AX, i
002E 83 E8 01 SUB AX, 1
0031 2B C3 SUB AX, BX
0033 05 1234 ADD AX, 1234h
Translating Languages
English: D is assigned the sum of A times B plus 10.
High-Level Language: D = A * B + 10