Skip to content

Fundamentals of Computer Systems

The CPU is the primary component that executes instructions. It consists of three main Sub-components:

ComponentFunction
Arithmetic Logic Unit (ALU)Performs arithmetic (add, subtract, multiply, divide) and logical (AND, OR, NOT, XOR) operations
Control Unit (CU)Coordinates all activities: fetches instructions, decodes them, and signals other components to execute
RegistersSmall, extremely fast storage locations inside the CPU used for temporary data during processing
RegisterPurpose
Program Counter (PC)Holds the memory address of the next instruction to be fetched
Memory Address Register (MAR)Holds the address in memory to be read from or written to
Memory Data Register (MDR)Holds data that has been read from or is about to be written to memory
Accumulator (ACC)Stores the results of ALU operations
Instruction Register (IR)Holds the current instruction being decoded and executed
Status Register (Flags)Stores flags such as Zero, Carry, Negative, Overflow from ALU operations
TypeFull NameVolatile?Read/WriteSpeedTypical Use
RAMRandom Access MemoryYesBothFastMain memory, running programs
ROMRead Only MemoryNoRead onlySlower than RAMBoot-up instructions (BIOS/UEFI), firmware

RAM types:

  • SRAM (Static RAM): Uses flip-flop circuits. Faster, more expensive. Used for CPU cache (L1, L2, L3).
  • DRAM (Dynamic RAM): Uses capacitors. Slower, cheaper, needs refreshing. Used as main memory.

ROM types:

  • PROM: Programmable once by the user.
  • EPROM: Erasable using UV light, reprogrammable.
  • EEPROM: Electrically erasable and reprogrammable.
Storage TypeTechnologySpeedCapacityCostVolatility
HDDMagnetic platters spinning at 5400/7200/10000 RPM80—160 MB/s500 GB — 20 TBLowNon-volatile
SSDNAND flash memory via SATA/NVMe500 MB/s — 7 GB/s (NVMe)256 GB — 4 TBMedium-HighNon-volatile
Flash MemoryNAND flash (USB drives, SD cards)10—300 MB/s1 GB — 1 TBMediumNon-volatile

DeviceInput TypeCommon Use Case
KeyboardText, commandsTyping documents, entering data
MousePointing, clickingGUI navigation, selecting objects
ScannerImage, document captureDigitising photos, OCR (Optical Character Recognition)
MicrophoneAudio/sound inputVoice recording, voice commands
Camera / WebcamImage, video captureVideo conferencing, photography
TouchscreenTouch gesturesMobile devices, kiosks, POS systems
Barcode ReaderLight reflection patternRetail checkout, inventory management
RFID ReaderRadio frequency signalAccess control, toll collection, tracking

Barcode Reader vs RFID:

FeatureBarcode ReaderRFID Reader
Line of sight requiredYesNo
Read rangeShort (contact to ~30 cm)Up to several metres
Data capacityLimited ( a number)Can store more data
CostLowerHigher
Read multiple at onceNoYes

DeviceOutput TypeCommon Use Case
MonitorVisual displayPrimary output for desktops/laptops
PrinterHard copy (paper)Inkjet (photo quality), Laser (high volume, fast)
SpeakerAudio outputMusic, alerts, multimedia
ProjectorLarge visual displayPresentations, classrooms, cinemas

Inkjet vs Laser Printer:

FeatureInkjetLaser
SpeedSlowerFaster
Print quality (text)GoodExcellent
Print quality (photos)BetterGood
Cost per pageHigherLower
Initial costLowerHigher
MechanismSprays liquid inkUses toner powder, heat

The Von Neumann architecture defines a computer system with:

  1. Single shared memory for both instructions and data (stored-program concept).
  2. CPU consisting of ALU, CU, and registers.
  3. System bus connecting CPU, memory, and I/O devices.
+---------+
| CPU |
| +-----+ |
| | CU | |
| +-----+ |
| | ALU | |
| +-----+ |
| |Regs | |
| +-----+ |
+----+----+
|
System Bus
|
+----+----+
| Memory |
| (RAM + |
| ROM) |
+---------+
|
System Bus
|
+----+----+
| I/O |
| Devices |
+---------+

Key principles:

  • Instructions and data are stored in the same memory.
  • Memory is addressed linearly.
  • Instructions are executed sequentially unless a branch/jump instruction changes the flow.
FeatureVon NeumannHarvard
Memory busSingle shared busSeparate instruction and data buses
MemoryOne memory for bothSeparate memories for instructions and data
Speed bottleneckYes (bus contention)No (parallel fetch)
ComplexitySimplerMore complex
Modern usageMost general-purpose CPUsDSPs, microcontrollers, CPU caches

The Von Neumann bottleneck arises because the CPU and memory share a single bus. The CPU is Often much faster than memory, so it spends time waiting for instructions and data to be fetched. This is why modern CPUs use cache memory (L1, L2, L3) to reduce the impact of the bottleneck.

Cache memory is a small, fast memory between the CPU registers and main memory (RAM):

Cache LevelLocationSizeSpeed
L1Inside CPU core32—128 KBFastest (~1 cycle)
L2Inside CPU (per core or shared)256 KB — 1 MBFast (~10 cycles)
L3Inside CPU (shared among all cores)2—64 MBModerate (~40 cycles)
RAMOutside CPU on motherboard4—128 GBSlowest (~100+ cycles)

When the CPU needs data, it checks L1 first, then L2, then L3, then RAM. If the data is found in Cache, it is a cache hit; otherwise it is a cache miss and the CPU must wait for the slower Memory.


This is the fundamental cycle by which the CPU processes every instruction.

  1. Fetch:
  • PC holds the address of the next instruction.
  • Address is copied from PC to MAR.
  • Instruction is fetched from memory address in MAR into MDR.
  • PC is incremented to point to the next instruction.
  • Instruction in MDR is copied to IR.
  1. Decode:
  • CU decodes the instruction in IR.
  • The CU determines which operation to perform and which operands are needed.
  1. Execute:
  • The instruction is executed (ALU performs calculations, data is moved, etc.).
  • Results are stored in the accumulator or written back to memory.
  • Status flags are updated as needed.
  • Cycle repeats from step 1.

Given memory starting at address 100:

AddressInstruction
100LOAD 5
101ADD 3
102STORE 6

Execution trace:

StepActionPCMARMDRIRACC
FetchPC(100) -> MAR; Mem[MAR] -> MDR; PC = 101; MDR -> IR101100LOAD 5LOAD 5?
DecodeCU decodes LOAD 5101100LOAD 5LOAD 5?
ExecuteMem[5] -> ACC101100LOAD 5LOAD 5M[5]
FetchPC(101) -> MAR; Mem[MAR] -> MDR; PC = 102; MDR -> IR102101ADD 3ADD 3M[5]
DecodeCU decodes ADD 3102101ADD 3ADD 3M[5]
ExecuteACC = ACC + Mem[3]102101ADD 3ADD 3M[5]+M[3]
FetchPC(102) -> MAR; Mem[MAR] -> MDR; PC = 103; MDR -> IR103102STORE 6STORE 6M[5]+M[3]
DecodeCU decodes STORE 6103102STORE 6STORE 6M[5]+M[3]
ExecuteACC -> Mem[6]103102STORE 6STORE 6M[5]+M[3]

Software that manages and controls hardware and provides a platform for application software.

TypeDescriptionExamples
Operating System (OS)Manages all hardware and software resourcesWindows, macOS, Linux, Android, iOS
Utility ProgramsPerform specific maintenance tasksDisk defragmenter, antivirus, file manager, backup tool

Software designed for end-users to perform specific tasks.

TypeDescriptionExamples
General-purposeWidely used across many domainsWord processors, spreadsheets, web browsers
Special-purposeDesigned for a specific fieldAccounting software, CAD, medical imaging
Custom/bespokeWritten for a specific organisationA company”s payroll system
FunctionDescription
Memory ManagementAllocates and deallocates memory space, uses virtual memory (swap space on disk to extend RAM), manages paging and segmentation
Process ManagementSchedules CPU time among processes, handles multitasking (time-sharing), manages process creation and termination
File ManagementOrganises files in directories/folders, handles file naming, access control, and storage allocation
User InterfaceProvides CLI (Command Line Interface) or GUI (Graphical User Interface) for user interaction
Device ManagementUses device drivers to communicate with hardware, manages I/O operations
SecurityUser authentication, access control, firewall integration

Command Line Interface (CLI):

  • User types commands using a keyboard.
  • Requires memorisation of commands and syntax.
  • Efficient for experienced users; supports scripting and automation.
  • Examples: Windows Command Prompt, Linux bash, macOS Terminal.

Graphical User Interface (GUI):

  • Users interact with visual elements (windows, icons, menus, buttons).
  • Intuitive and easy to learn; does not require memorising commands.
  • Uses pointing devices (mouse, touchscreen).
  • Consumes more system resources than CLI.
  • Examples: Windows Explorer, macOS Finder, Android/iOS home screens.

Menu-Driven Interface:

  • User selects options from a predefined list of menus.
  • Common in ATMs, self-service kiosks, and embedded systems.
  • Limited flexibility but very easy to use for specific tasks.

Virtual memory is a memory management technique that uses secondary storage (hard disk/SSD) as an Extension of RAM. When physical RAM is full, the operating system moves less frequently used pages (data blocks, 4 KB) from RAM to a designated area on disk called the swap space or page file. When those pages are needed again, they are swapped back into RAM.

AspectAdvantageDisadvantage
CapacityAllows running more/larger programs than physical RAM aloneDisk access is much slower than RAM (thousands of times slower)
CostEffectively increases memory without buying more RAMExcessive swapping (thrashing) severely degrades performance
ImplementationTransparent to the user and applicationsRequires disk space to be reserved

Thrashing occurs when the system spends more time swapping pages in and out of memory than Executing actual instructions. This happens when the system is overloaded with too many processes Competing for insufficient RAM.


Digits: 0, 1. Each digit is a bit. 8 bits = 1 byte.

DecimalBinary
00000 0000
10000 0001
20000 0010
50000 0101
100000 1010
2551111 1111

Digits: 0—9, A(10), B(11), C(12), D(13), E(14), F(15). Each hex digit represents exactly 4 bits.

HexBinaryDecimal
000000
100011
910019
A101010
F111115
100001 000016
FF1111 1111255
1000001 0000 0000256

Each decimal digit (0—9) is represented by its 4-bit binary equivalent.

DecimalBCD
00000
91001
150001 0101
1270001 0010 0111

Decimal to Binary: Repeatedly divide by 2, record remainders from bottom to top.

Decimal to Hexadecimal: Repeatedly divide by 16, record remainders.

Binary to Hexadecimal: Group bits in groups of 4 from the right, convert each group.

Hexadecimal to Binary: Replace each hex digit with its 4-bit binary equivalent.

Decimal to BCD: Replace each decimal digit with its 4-bit binary equivalent.

Worked Example: Decimal 185 to Binary, Hex, and BCD

To binary:

185÷2=92185 \div 2 = 92 R 11 92÷2=4692 \div 2 = 46 R 00 46÷2=2346 \div 2 = 23 R 00 23÷2=1123 \div 2 = 11 R 11 11÷2=511 \div 2 = 5 R 11 5÷2=25 \div 2 = 2 R 11 2÷2=12 \div 2 = 1 R 00 1÷2=01 \div 2 = 0 R 11

Reading remainders from bottom to top: 18510=101110012185_{10} = 10111001_2

To hexadecimal:

185÷16=11185 \div 16 = 11 R 99. 11=B11 = B. So 18510=B916185_{10} = B9_{16}

To BCD:

1851850001 1000 0101185 \to 1 \to 8 \to 5 \to 0001\ 1000\ 0101

18510=000110000101BCD185_{10} = 000110000101_{BCD}


ASCII (American Standard Code for Information Interchange)

Section titled “ASCII (American Standard Code for Information Interchange)”
  • 7-bit code, extended to 8-bit (Extended ASCII).
  • Represents 128 characters (0—127): uppercase letters (65—90), lowercase letters (97—122), digits (48—57), control characters (0—31), symbols.
  • Each character stored as 1 byte (8 bits) with the MSB unused or used for parity.
CharacterASCII (decimal)ASCII (binary)
‘A’650100 0001
’Z’900101 1010
’a’970110 0001
’0’480011 0000
Space320010 0000
  • Supports characters from all languages, symbols, and emoji.
  • UTF-8 encoding: variable-length (1—4 bytes). Backward-compatible with ASCII (first 128 characters identical).
  • UTF-16: 2 or 4 bytes per character.
  • UTF-32: fixed 4 bytes per character.