Fundamentals of Computer Systems (8hrs) · Computer Fundamentals & Emerging Technologies

Machine language

Watch lectures

Machine language

1. Definition

Machine language (machine code) is the lowest level programming language: a sequence of binary codes (0s and 1s) that the CPU can decode and execute directly, without any translation. Each instruction is a pattern of bits that the control unit's decoder understands, so a machine language program is essentially the hardware's own vocabulary.

  • It is the only language a CPU truly executes — every other language is eventually translated into it.
  • It is machine dependent (non-portable): an Intel x86 program cannot run on ARM and vice versa.
  • Human-readable form of the same codes is hexadecimal (e.g. 3Eh 05h instead of 0011 1110 0000 0101).

2. Instruction Format

A machine instruction is divided into fields:

 ┌───────────────┬──────────────────┬───────────────────┐
 │   OPCODE      │  OPERAND 1       │  OPERAND 2        │
 │ what to do    │  address/register│  address/register │
 └───────────────┴──────────────────┴───────────────────┘
        4-8 bits           varies depending on format

Opcode selects the operation (add, load, jump …); the operand field(s) identify the data — as a register number, a memory address or an immediate value.

Number of address fields gives the naming convention:

Format Example Meaning
3-address ADD R1, R2, R3 R1 ← R2 + R3 — most general, longest instruction
2-address ADD R1, R2 R1 ← R1 + R2 — one operand destroyed, common in CISC
1-address ADD 500 AC ← AC + M[500] — accumulator machine
0-address ADD pops two stack values, pushes sum — stack machine

3. Worked Example

Program: result = a + b on a hypothetical 16-bit machine with opcode 0001 = LOAD, 0010 = ADD, 0011 = STORE (8-bit address field):

Assembly Machine code (binary) Hex
LOAD 1000 0001 0000 0000 1000 1008H
ADD 1001 0010 0000 0000 1001 2009H
STORE 1002 0011 0000 0000 1010 300AH

Real examples: on the 8085, MOV A, B is 78H, MVI A, 05H is 3EH 05H; on ARM, ADD R0, R1, R2 assembles to E0810002H.

4. Categories of Machine Instructions

  • Data transfer — LOAD, STORE, MOV, PUSH, POP, IN, OUT.
  • Arithmetic / logical — ADD, SUB, MUL, DIV, AND, OR, NOT, XOR, CMP, shifts.
  • Control transfer — JMP, JZ, JNZ, CALL, RET, HLT.
  • Machine control / I-O — interrupts, reset, port I-O.

5. Advantages and Limitations

Advantages Limitations
Executes fastest — no translation at run time Almost impossible to write or debug by hand; a huge number of bits
Direct, total control of the hardware Machine dependent — no portability at all
Very compact code; no translator software needed Programmer must know the exact architecture, registers and opcodes
Only option for boot code and firmware One small mistake corrupts everything; hard to modify

6. Where Machine Language Still Appears

  • Boot ROM / BIOS / UEFI and POST routines that run before any compiler exists.
  • Microcode inside the CPU that implements complex instructions.
  • The final output of every compiler/assembler and of a JIT compiler.
  • Disassembly during debugging, reverse engineering and malware analysis.
  • Time-critical interrupt service routines and device initialisation in embedded systems.

7. Exam Points

  • Define machine language and explain the instruction format (opcode, operand) — 5 marks, frequent.
  • Convert a given assembly instruction into its machine code / hex — 3-5 marks.
  • Explain 0-, 1-, 2- and 3-address instruction formats with examples — 5 marks.
  • Advantages and limitations of machine language — 3-5 marks.
  • Why is machine language called the first generation language and why is it not portable? — 3 marks.
Budget AppAndroid App

Pocketly on Android

Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.

← All Computer Fundamentals & Emerging Technologies modules