Blog
01 · Software & Hardware FundamentalsPart 0116 min read

What Is Software and How Do Computers Execute Code? A Complete Engineering Guide

Learn how software bridges human logic and physical silicon: from transistors and binary bytes to CPU registers, RAM addressing, the Fetch-Decode-Execute cycle, OS kernel system calls, and modern full-stack execution.

Emirhan Uluksar
Emirhan Uluksar

Founder & Principal Software Architect · Digital HAT

5 views
What Is Software and How Do Computers Execute Code? A Complete Engineering Guide

Hi, I'm Emirhan Uluksar. When interviewing junior engineers or mentoring developers who are just starting out, the most common gap I see is that people jump straight into memorizing framework syntax (React, ASP.NET, Spring) without understanding what physically happens inside the machine when their code runs. A building without a deep foundation cracks under production load.

In this comprehensive guide—assuming zero prior background—we will walk step-by-step from microscopic transistors and binary bits all the way to CPU registers, RAM addressing, OS kernel system calls, and how a modern multi-tier application executes a user request in milliseconds.

What You Will Master in This Guide:
1. Why silicon hardware uses binary (0 and 1) and how bits, bytes, and ASCII/UTF-8 encodings work.
2. The core equation of software: Data Structures + Algorithms (Instructions).
3. The hardware speed hierarchy: CPU Registers & L1/L2/L3 Cache vs. Main Memory (RAM) vs. NVMe SSD.
4. A step-by-step simulation of the CPU Fetch → Decode → Execute loop.
5. Operating System architecture: Kernel Mode vs. User Mode and System Calls (syscalls).
6. Real-World Trace: The 8-step journey that happens in 120ms when a user taps "Confirm Order" on their phone.
Software and Hardware Execution Stack: Application, OS Kernel, CPU and RAM

1. Why Do Computers Only Understand 0 and 1?

Inside your phone or server processor (CPU) sit billions of microscopic transistors (over 20 billion on a modern 3nm chip). Each transistor acts as an ultra-fast electrical switch:

  • When voltage flows across the gate, the state is 1 (True / High).
  • When no voltage flows, the state is 0 (False / Low).

A single 0 or 1 is called a Bit (Binary Digit). Grouping 8 bits together creates 1 Byte, which yields 2⁸ = 256 distinct combinations (values 0 through 255):

# 8-Bit (1 Byte) Binary Representations in Decimal and ASCII:
Binary         | Decimal | ASCII Character
---------------|---------|----------------
01000100       | 68      | 'D'
01001000       | 72      | 'H'
00110001       | 49      | '1'
11111111       | 255     | Maximum 1-Byte Unsigned Integer

# Memory Capacity Units (Scaling by 1,024 at each tier):
1 Byte (B)      = 8 Bits (Single ASCII character)
1 Kilobyte (KB) = 1,024 Bytes (Short configuration file)
1 Megabyte (MB) = 1,024 KB    (High-resolution image)
1 Gigabyte (GB) = 1,024 MB    (Server RAM allocation)
1 Terabyte (TB) = 1,024 GB    (Enterprise database volume)

2. The Hardware Speed Hierarchy: SSD vs. RAM vs. CPU Cache

Why doesn't the CPU execute code directly from your 1 TB NVMe SSD? Because of a massive **500x latency gap**:

Hardware Tier Role in Execution Access Latency Persistent When Powered Off?
1. CPU Registers & L1/L2/L3 Cache SRAM cells etched directly inside the CPU die holding active loop counters and arithmetic operands. 0.5 – 4 Nanoseconds No (Volatile)
2. Main Memory (RAM) Holds the active machine instructions, Stack frames, and Heap objects of running processes. Every byte has a hex address (e.g. 0x7ffee4b2). ~60 – 100 Nanoseconds No (Volatile)
3. NVMe SSD / Disk Stores application binaries, OS files, and PostgreSQL data pages permanently. ~50,000 Nanoseconds (500x slower than RAM!) Yes (Non-Volatile)

3. The CPU Heartbeat: Fetch → Decode → Execute

A 3.5 GHz processor ticks 3.5 billion times per second. Using its internal Program Counter (PC) register, it continuously repeats three hardware stages:

+-------------------------------------------------------------------------+
|                   CENTRAL PROCESSING UNIT (CPU)                         |
|                                                                         |
|  1. FETCH   : Read the next machine instruction from the RAM address    |
|               stored in the Program Counter (PC) into the CPU.          |
|  2. DECODE  : The Control Unit decodes the binary opcode                |
|               (e.g., "ADD register EAX and register EBX").              |
|  3. EXECUTE : The Arithmetic Logic Unit (ALU) performs the calculation, |
|               writes the result to the target register, and advances PC.|
+-------------------------------------------------------------------------+

// High-level C# invoice calculation written by a developer:
int subtotal = 1000;
int tax = 200;
int total = subtotal + tax;

// What the CPU physically executes after compilation:
// MOV EAX, 1000        -> Load 1000 into CPU register EAX
// MOV EBX, 200         -> Load 200 into CPU register EBX
// ADD EAX, EBX         -> ALU computes 1000 + 200 = 1200 in EAX
// MOV [0x7ffe04], EAX  -> Store 1200 into RAM address 0x7ffe04 ('total')

4. Operating System Architecture: Kernel Mode vs. User Mode

Why doesn't a crash in one application freeze your entire server? Because modern CPUs enforce two hardware privilege rings:

  1. Kernel Mode (Ring 0 — Unrestricted): Only the OS Kernel (Linux, Windows NT, macOS XNU) runs here. It has direct control over physical RAM pages, NVMe disk blocks, and network sockets.
  2. User Mode (Ring 3 — Sandboxed): Your .NET Web API, PostgreSQL process, and web browser run here. Whenever your code needs to read a file or open a TCP socket, it cannot touch the hardware directly—it must issue a controlled System Call (syscall) to the kernel (open(), read(), write(), socket()).

5. Real-World Trace: What Happens in 120ms When You Click "Confirm Order"?

[1. Client Device]   Touch event -> Browser JS serializes JSON payload -> Encrypts via TLS 1.3
         │
         ▼  (TCP packets travel over fiber-optic routers to your cloud server IP)
[2. Server NIC/OS]   Linux Kernel receives packets on port 443 -> Forwards to Nginx Reverse Proxy
         │
         ▼
[3. .NET 9 Web API]  OrderController deserializes JSON in RAM, validates stock and balance on CPU
         │
         ▼
[4. PostgreSQL SSD]  Database writes the transaction to Write-Ahead Log (WAL) on NVMe SSD (COMMIT)
         │
         ▼
[5. HTTP Response]   Server returns "HTTP 201 Created" -> Phone screen renders order confirmation!

Did you find this engineering guide helpful?

Give it a like or share it with your team and network.

5 views
Share This Guide: