COA Notes
Introduction to machine language, binary instruction encoding, and the relationship between assembly and machine code.
Introduction
Machine language is the only language a processor truly understands — raw binary patterns that directly control hardware operations. Every other language (Assembly, C, Python) must eventually be translated into machine language before the CPU can execute it. Understanding machine language gives you the deepest possible insight into how software meets hardware.
What is Machine Language?
Machine language consists of binary instruction words — fixed patterns of 0s and 1s that encode:
- What operation to perform (opcode)
- What data to use (operand specifiers)
- Where to store results (destination)
Each instruction is just a number. When the CPU fetches the value 0x01284820 from memory, it interprets it as "ADD register 9, register 9, register 8" (in MIPS). There's nothing inherently "instruction-like" about this bit pattern — it's the CPU's decode logic that gives it meaning.
Machine Language vs Assembly Language
| High-level | c = a + b; |
| Assembly | ADD R3, R1, R2 |
| Machine code | 00000000001000100001100000100000 |
| Hexadecimal | 0x00221820 |
Assembly language is just human-readable machine language — a one-to-one mapping where each assembly mnemonic corresponds to exactly one machine instruction. An assembler converts assembly to machine code.
Encoding Example: MIPS R-Type
The MIPS instruction ADD $t1, $t2, $t3 (add registers t2 and t3, put result in t1):
| Fields | opcode rs rt rd shamt funct |
| Bits | 000000 01010 01011 01001 00000 100000 |
| Meaning | R-type $t2 $t3 $t1 0 ADD |
| Binary | 00000001010010110100100000100000 |
| Hex | 0x014B4820 |
This 32-bit number IS the instruction. That's what lives in memory and what the CPU fetches.
Encoding Example: MIPS I-Type
The instruction LW $t0, 12($s0) (load word from address s0+12 into t0):
| Fields | opcode rs rt immediate |
| Bits | 100011 10000 01000 0000000000001100 |
| Meaning | LW $s0 $t0 12 |
| Binary | 10001110000010000000000000001100 |
| Hex | 0x8E08000C |
How the CPU Interprets Machine Code
When the CPU fetches an instruction:
- Read the opcode field — determines instruction type and format
- Identify the format — R-type, I-type, or J-type (in MIPS)
- Extract operand fields — register numbers, immediate values, addresses
- Generate control signals — the opcode maps to specific ALU operations, register enables, etc.
| Fetched bits | 0x00221820 |
| Opcode = 000000 | R-type format |
| funct = 100000 | ADD operation |
| rs = 00001 | Register 1 ($at) |
| rt = 00010 | Register 2 ($v0) |
| rd = 00011 | Register 3 ($v1) |
Program in Machine Language
A simple program to add 5 + 3:
To the CPU, this is just three 32-bit numbers stored at consecutive memory locations. It fetches each one in sequence, decodes it, and executes.
Why We Don't Program in Machine Language
Writing 0x014B4820 instead of ADD $t1, $t2, $t3 is:
- Error-prone (one wrong bit = completely different instruction)
- Unreadable (can't easily see what a program does)
- Tedious (must manually calculate addresses for branches)
- Platform-specific (different binary encoding for each CPU architecture)
That's why assembly language exists — same information, human-readable form.
Endianness: Byte Order in Memory
A 32-bit instruction stored in memory can be arranged two ways:
Big-Endian (most significant byte at lowest address):
Little-Endian (least significant byte at lowest address):
x86 is little-endian; many RISC architectures are big-endian (or configurable).
Key Takeaways
- Machine language is the binary encoding that the CPU directly executes
- Each instruction is a fixed-size binary number with fields for opcode and operands
- Assembly language is a human-readable one-to-one mapping of machine code
- The CPU's decode logic interprets bit patterns as operations and operand specifiers
- Different ISAs have completely different binary encodings (x86 ≠ ARM ≠ MIPS)
- Understanding machine encoding helps with debugging, reverse engineering, and hardware design
- Endianness determines byte order when multi-byte values are stored in memory
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Machine Language Basics.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Computer Organization & Architecture topic.
Search Terms
computer-organization, computer organization & architecture, computer, organization, instruction, set, architecture, machine
Related Computer Organization & Architecture Topics