Assembly-Level Machine Organisation

Assembly language is a human-readable way to write instructions that a processor can execute. It sits close to machine code: each assembly instruction usually corresponds to one machine instruction for a particular processor architecture.

Machine code and assembly

  • Machine code is the binary instruction format the CPU executes.

  • Assembly language uses short names, called mnemonics, to make those instructions easier to read.

  • An assembler translates assembly instructions into machine code.

Assembly is specific to an instruction set architecture (ISA). Code written for one ISA, such as ARM, generally won’t run directly on an x86 processor.

Registers and operands

Assembly instructions often operate on values in CPU registers.

A simplified instruction might look like:

ADD R1, R2, R3

This means: add the values in registers R2 and R3, then put the result in R1. The exact syntax depends on the processor and assembler.

A register is much faster for the CPU to access than data stored in main memory, but a processor has only a limited number of registers.

Common instruction types

  • Data movement: copy data between registers, memory and other locations.

  • Arithmetic: add, subtract, multiply or divide values.

  • Logic: perform operations such as AND, OR, NOT and XOR.

  • Comparison: compare values and set status information.

  • Branching: change which instruction runs next.

  • Input/output: access devices, often through OS services or device-specific mechanisms.

Load/store organisation

Many processor architectures use a load/store design:

  • A load instruction copies data from memory into a register.

  • Arithmetic and logic instructions operate on registers.

  • A store instruction copies a result from a register back to memory.

This means the CPU generally does not perform arithmetic directly on values in main memory.

A simple instruction sequence

The following is generic pseudocode rather than code for a specific processor:

LOAD R1, [A]       ; copy the value at memory location A into R1
LOAD R2, [B]       ; copy the value at memory location B into R2
ADD  R3, R1, R2    ; add the two register values; place result in R3
STORE [C], R3      ; write the result to memory location C

The sequence reads two values, adds them and stores the result.

Program flow and branching

The CPU normally executes instructions in order. A branch changes the next instruction address.

  • An unconditional branch always jumps to another location.

  • A conditional branch jumps only if a condition is met, such as a comparison being true.

Branches are used to implement decisions and loops.

The program counter

The program counter (PC) holds the address of the next instruction. During normal execution, it advances as instructions are fetched. A branch or function call can change its value.

This connects assembly to the CPU’s fetch–decode–execute cycle: the processor uses the PC to find an instruction, decodes it and executes it.

Assembly and operating systems

Programs commonly use system calls to request services from the operating system, such as opening a file or creating a process. A system call transfers execution into the OS kernel so it can perform the requested operation under controlled rules.

Key terms to remember

Assembly language · machine code · assembler · ISA · mnemonic · register · load · store · branch · program counter · system call

Check your understanding

  1. What does an assembler do?

  2. Why is assembly language specific to a processor ISA?

  3. In a load/store design, where does arithmetic usually happen?

  4. What does the program counter hold?

  5. What is the difference between a conditional and unconditional branch?

Answers:

  1. It translates assembly instructions into machine code.

  2. Different ISAs define different instructions, registers and machine-code formats.

  3. In CPU registers.

  4. The address of the next instruction.

  5. An unconditional branch always jumps; a conditional branch jumps only when its condition is met.