Programming languages exist at different levels of abstraction from the underlying hardware. Lower-level languages are closer to the hardware; higher-level languages are closer to natural language and further from hardware.
| Level | Example | Abstraction |
|---|---|---|
| Low-level | Machine code, Assembly | Close to hardware — operates directly on CPU registers and memory |
| High-level | Python, Java, C++ | Far from hardware — abstract instructions, portable across platforms |
Machine code is the only language a CPU can directly execute. It consists entirely of binary digits (0s and 1s) — every instruction is encoded as a binary pattern that the CPU's control unit decodes and executes.
Example machine code instruction (8-bit hypothetical): 10110000 01100101 — the first byte might be the opcode (operation) and the second byte the operand (data or address).
Each machine code instruction contains:
| Field | Purpose | Example (binary) |
|---|---|---|
| Opcode | Specifies operation (ADD, LOAD, STORE, JUMP) | 1011 (4 bits) |
| Operand | Register number / memory address / immediate value | 00000101 (8 bits) |
Assembly language is a low-level programming language that uses mnemonics (human-readable abbreviations) to represent machine code instructions. Each assembly instruction corresponds one-to-one with a machine code instruction.
Assembly language is architecture-specific — assembly code for an x86 processor cannot run directly on an ARM processor.
MOV (move/copy), ADD (add), SUB (subtract), LDR (load from memory), STR (store to memory), CMP (compare), B (branch/jump).LOOP: or START:.; to annotate code.; Load two values, add them, store result LDR R1, 100 ; Load value from memory address 100 into R1 LDR R2, 101 ; Load value from memory address 101 into R2 ADD R3, R1, R2 ; R3 = R1 + R2 STR R3, 102 ; Store R3 into memory address 102 HALT ; Stop the program
| Mnemonic | Operation | Example |
|---|---|---|
LDR Rx, <address> | Load contents of memory address into register Rx | LDR R1, 200 |
STR Rx, <address> | Store contents of Rx into memory address | STR R1, 200 |
MOV Rx, <operand> | Copy operand value (or register) into Rx | MOV R0, #5 |
ADD Rx, Ry, Rz | Rx = Ry + Rz | ADD R3, R1, R2 |
SUB Rx, Ry, Rz | Rx = Ry − Rz | SUB R3, R1, R2 |
CMP Rx, <operand> | Compare Rx with operand (sets condition flags) | CMP R1, #0 |
B <label> | Unconditional branch (jump) to label | B LOOP |
BEQ <label> | Branch if equal (zero flag set) | BEQ END |
BNE <label> | Branch if not equal | BNE LOOP |
BGT <label> | Branch if greater than | BGT BIGGER |
BLT <label> | Branch if less than | BLT SMALLER |
HALT | Stop execution | HALT |
AND Rx, Ry, Rz | Bitwise AND: Rx = Ry AND Rz | AND R1, R2, R3 |
ORR Rx, Ry, Rz | Bitwise OR: Rx = Ry OR Rz | ORR R1, R2, R3 |
EOR Rx, Ry, Rz | Bitwise XOR: Rx = Ry XOR Rz | EOR R1, R2, R3 |
LSL Rx, Ry, <n> | Logical shift left Ry by n bits, result in Rx | LSL R1, R1, #2 |
LSR Rx, Ry, <n> | Logical shift right Ry by n bits, result in Rx | LSR R1, R1, #1 |
An assembler is a program that translates assembly language code into machine code. It replaces each mnemonic with its binary equivalent opcode and converts labels and addresses to their binary representations.
Despite the existence of high-level languages, assembly is still used because:
| Feature | Machine Code | Assembly Language | High-level Language |
|---|---|---|---|
| Readability | None — binary | Low — mnemonics | High — near natural language |
| Portability | None — CPU specific | None — architecture specific | High — portable (with compiler) |
| Translation needed | None — direct execution | Assembler | Compiler or interpreter |
| Execution speed | Fastest | Very fast | Slower (abstraction overhead) |
| Development speed | Very slow | Slow | Fast |
| Level of control | Maximum | High | Low |
| Typical use | Generated by assembler/compiler | Device drivers, bootloaders, embedded | Application software, web, games |
8 questions · 20 marks · instantly marked
| Term | Definition |
|---|