Assembly language
1. Definition
Assembly language is a low-level language that represents machine instructions in a human-readable, symbolic form using mnemonics (short names such as MOV, ADD, JMP) instead of binary opcodes. It is translated into machine language by a program called an assembler. There is (almost) a one-to-one correspondence between an assembly instruction and a machine instruction, which is why it is called a symbolic machine language.
Machine language : 0011 1110 0000 0101 (3E 05 H)
Assembly language: MVI A, 05H
Meaning : put the value 5 into the accumulator
2. Elements of an Assembly Program
| Element | Purpose | Example |
|---|---|---|
| Mnemonic (opcode) | The operation | MOV, ADD, INR, JZ |
| Operands | Data, register or address the opcode works on | A, B, 2050H |
| Label | A name for an address, used for branches and data | LOOP:, SUM: |
| Directive / pseudo-op | Instruction to the assembler, generates no code | ORG, EQU, DB, DW, END |
| Comment | Documentation for the reader | ; sum in A |
3. Addressing Modes
| Mode | Meaning | Example |
|---|---|---|
| Immediate | Data is part of the instruction | MVI A, 05H |
| Register | Operand is a register | MOV A, B |
| Direct | Address of the operand is given | LDA 2050H |
| Indirect | A register pair holds the address | MOV A, M (M = memory at H-L) |
| Indexed / based | Address = base + index + displacement | MOV AX, [BX+SI+4] |
| Relative | Target is given as an offset from PC | JNZ LOOP |
| Implied / stack | Operand is implicit | CMA, PUSH B, RET |
4. Sample Program (8085-style — add five numbers)
ORG 2000H ; start of program
LXI H, 2050H ; H-L = address of first number
MVI C, 05H ; C = counter = 5
MVI A, 00H ; A = sum = 0
LOOP: ADD M ; A = A + memory[H-L]
INX H ; point to next number
DCR C ; counter = counter - 1
JNZ LOOP ; repeat while counter is not zero
STA 2060H ; store the sum
HLT ; stop
5. How the Assembler Works
An assembler translates mnemonics into machine code in (usually) two passes:
- Pass 1 builds a symbol table — each label is assigned the address of the instruction/data following it; this resolves forward references (a jump to a label that appears later).
- Pass 2 substitutes opcode codes for mnemonics and label addresses for symbols, and emits the object code, listing, and error diagnostics.
A macro assembler also expands user-defined macros, and a cross assembler runs on one machine but generates code for another (typical in embedded development).
6. Assembly vs High-Level Language
| Aspect | Assembly language | High-level language (C, Java) |
|---|---|---|
| Level | Low (near hardware) | High (near problem domain) |
| Translation | Assembler, 1 mnemonic ↔ 1 instruction | Compiler, 1 statement ↔ many instructions |
| Portability | None — CPU specific | Good to excellent |
| Program length | Long, verbose | Short, readable |
| Speed of code | Fastest, minimal overhead | Slightly slower, compiler-dependent |
| Hardware access | Full (registers, ports, interrupts) | Restricted (usually through libraries) |
| Development time | Very long, error-prone | Short, easier to debug |
| Debugging | Difficult (registers, flags) | Easier (variables, functions) |
7. Advantages, Limitations and Uses
Advantages: gives complete control of CPU registers, flags, ports and interrupts; produces the smallest and fastest code; essential where timing and memory are critical; makes the hardware behaviour visible (good for learning).
Limitations: machine dependent, so a program must be rewritten for each CPU; long development and debugging time; unfriendly syntax; easy to introduce subtle bugs.
Applications: embedded firmware and microcontrollers, bootloaders, device drivers, real-time interrupt handling, cryptographic and DSP inner loops, low-level system code, and reverse engineering / malware analysis.
8. Exam Points
- Define assembly language and list its elements (mnemonic, label, directive, operand) — 5 marks.
- Explain any five addressing modes with examples — 5 marks, very frequent.
- Difference between assembler and compiler; assembly vs high-level language — 5 marks.
- Write a short assembly program (sum of N numbers / largest of N numbers) — 5-7 marks.
- Explain the two-pass assembler with a symbol table — 5 marks.
- Why is assembly language called a low-level language? — 2-3 marks.