How Computers Work
BeginnerLesson 3 of 7 in Introduction to Computer Science Course
What you will learn
- Identify the main hardware parts of a computer, explain the stored-program idea behind the von Neumann architecture, and describe how buses and input and output devices connect everything.
- Identify the main parts of a computer and the stored-program ideaDistinguish hardware from software and describe the von Neumann architecture: a processor, one memory for both instructions and data, input and output, and the connections between them.
- Explain how buses carry addresses, data and control signalsDescribe the address, data and control parts of the system bus, follow a memory read and write, and calculate how bus width limits addressable memory and transfer speed.
- Classify input and output devices and explain how they connect to the CPUSort devices by their role, explain conversion between analog signals and digital data, and describe how controllers, drivers, interrupts and direct memory access let slow devices work with a fast processor.
- Identify the main parts of a computer and the stored-program idea
- Show how transistors and logic gates compute with bits, name the parts of the CPU, trace the fetch-decode-execute cycle, and explain what makes one processor faster than another.
- Use logic gates to see how hardware computes with bitsRead the truth tables of the basic logic gates, work out the output of a small circuit, and explain how gates built from transistors add numbers and store bits.
- Name the parts of the CPU and what each one doesDescribe the control unit, the arithmetic logic unit, the general-purpose and special registers, the clock and the cores, and the job each one does when a program runs.
- Trace the fetch-decode-execute cycleFollow the steps the CPU repeats for every instruction, track the registers through a short program, and explain how jumps and interrupts change what runs next.
- Explain what makes a processor fasterCompare the effects of clock speed, number of cores, cache size and pipelining, and estimate how each one changes the time a task takes.
- Use logic gates to see how hardware computes with bits
- Describe machine code and instruction sets, read a short assembly program, and explain how compilers, assemblers, linkers and interpreters turn source code into a running program.
- Read machine code and assembly languageExplain what a machine instruction contains, why an instruction set ties programs to a processor family, and how assembly language makes machine code readable.
- Explain how compilers and interpreters turn source code into running programsCompare compiling and interpreting, follow the steps from a source file to an executable, and explain bytecode, virtual machines and why the same program can run on different computers.
- Read machine code and assembly language
- Compare main memory with the different kinds of secondary storage, explain the memory hierarchy and caching, and choose suitable storage for a task.
- Describe main memory and how it is addressedExplain RAM and ROM, volatility, byte addresses and capacity units, and why a program must be in main memory to run.
- Compare secondary storage technologiesExplain how hard disks, solid-state drives, flash media, optical discs, magnetic tape and cloud storage keep data, and choose storage by capacity, speed, cost, durability and portability.
- Explain the memory hierarchy and cachingOrder the levels from registers to archive storage by speed, size and cost, explain why caches work, and calculate how cache hits and misses affect the average access time.
- Describe main memory and how it is addressed
- Describe what an operating system does, how a computer starts, and how the operating system loads programs into memory, runs them on the processor and keeps them apart.
- Describe the role of the operating systemExplain how the operating system manages the processor, memory, storage and devices, provides a user interface and file system, and keeps users and programs secure.
- Follow how a computer starts and runs a programTrace the boot sequence, follow how the operating system loads a program into memory and starts it, and explain how virtual memory keeps programs apart and lets them use more memory than is installed.
- Describe the role of the operating system
How Computers Work study guide
1Computer parts and the paths between them
A computer becomes easier to understand when you separate the jobs its parts perform. Input brings in data, the processor follows stored instructions, memory supplies working contents, and output presents results. The connections matter as much as the components: follow an address, a value and a control signal to see how a processor reaches memory and devices, then see how slower devices request attention.
1.1 The parts that make a computer work
A computer accepts input, follows instructions to process it, stores data, and produces output. These roles apply to a laptop and to a controller hidden inside a washing machine. The difference is the task and the equipment attached to it.
Physical parts and programs
Hardware is the physical equipment. Software consists of programs and the data they work on. The CPU is the processor chip, not the whole computer case. A motherboard connects it to RAM, storage, a GPU, power and device ports. The GPU handles drawing and other work that applies similar operations to many values. A phone combines many of these functions in a system on a chip (SoC).
RAM holds instructions and data being used now. A storage drive keeps programs and saved files without power. In a computer described as having 16 GB of memory and a 512 GB SSD, the first capacity describes RAM and the second describes storage. A larger drive does not provide more working RAM.
A program stored as data
The von Neumann architecture has a CPU, main memory holding both instructions and data, input/output devices, and buses connecting them. John von Neumann described this design in the 1945 "First Draft of a Report on the EDVAC." Its central idea is the stored program: instructions are binary values in memory, ready for the CPU to fetch.
Earlier machines such as ENIAC were set up for tasks with switches and cables. Loading a new program lets a stored-program machine change jobs without rewiring. The Manchester Baby ran a program in rewritable electronic memory on June 21, 1948.
Memory does not attach a meaning to each pattern. The byte 01000001 can represent the number 65, the ASCII letter "A", or part of an instruction. What the CPU or program does with the pattern determines its meaning. During an instruction fetch, the CPU treats the fetched pattern as an instruction.
Why the processor can wait
Instructions and data share the route between the CPU and main memory. Memory also supplies them more slowly than the CPU can use them. This restriction is the von Neumann bottleneck. A fast processor can therefore spend time waiting for the next value. Small, fast caches keep useful copies near the CPU and reduce many of these waits.
| Design | Instructions and data | Useful consequence |
|---|---|---|
| Von Neumann | Share main memory and its path | One memory holds a changing mixture of code and data. |
| Harvard | Have separate memories and paths | An instruction and a data value can be fetched together. |
Small microcontrollers and signal processors often use a Harvard design. Modern general-purpose CPUs combine the ideas: shared main memory, but separate level 1 instruction and data caches.
Computers inside other devices
An embedded system does a dedicated job inside a larger device. A thermostat reads a temperature sensor, processes the reading, and controls heating. Its stored program usually stays in non-volatile memory. The processor, memory and input/output roles are still present, even without a keyboard, screen or full desktop operating system.
Key Takeaways
- Hardware is physical equipment; software supplies programs and data.
- The CPU is one component, distinct from RAM, storage and the computer case.
- A stored-program computer fetches binary instructions held in memory.
- A bit pattern gets its meaning from how it is used.
- Caches reduce waiting caused by the CPU–memory bottleneck.
1.2 How addresses, values and commands travel
A processor needs three things to access memory: a location, the value to transfer, and a command telling memory what to do. Keeping these roles separate makes a bus transaction much easier to follow.
Three roles on a classic system bus
A bus is a shared communication path. In a classic parallel system bus, several wires or circuit-board tracks carry bits at the same time.
| Bus part | What it carries | Direction in a CPU memory access |
|---|---|---|
| Address bus | The location to use | From CPU toward memory or a device |
| Data bus | An instruction or data value | Toward CPU for a read; away for a write |
| Control bus | Read, write, timing and interrupt signals | Depends on the signal |
An address names a location; it is not the value stored there. Address 200 can hold 7 today and 9 later without changing its address. A useful comparison is a numbered mailbox: the number identifies the box, while its contents can change.
Follow a read and a write
To read address 200, the CPU puts 200, binary 11001000, on the address bus and sends a read command on the control bus. Memory returns the value at that location, here 7, on the data bus. The CPU copies it into a register.
To write 9 at address 201, the CPU puts 201 on the address bus, 9 on the data bus, and a write command on the control bus. Memory replaces the contents of location 201. Sending 201 on the data bus would send the wrong value; the address and the contents have different jobs.
Address width limits the number of locations
With address bits there are different addresses. If each address names one byte, that is also the number of addressable bytes.
- 16 bits give addresses, or 64 KiB.
- 32 bits give addresses, or 4 GiB.
- Increasing from 20 to 21 bits doubles capacity from 1 MiB to 2 MiB.
Every extra bit doubles the combinations. Doubling the bit count from 16 to 32 multiplies the location count by ; it does not merely double it. This calculation gives an addressing limit, not the amount of RAM actually installed.
Data width limits each transfer
A 64-bit data path carries 8 bytes in one transfer. An 8-bit path needs four transfers to carry a 4-byte value. Bandwidth measures how much data can move per second:
At 1 billion transfers per second, an 8-byte path carries 8 billion bytes per second, or 8 GB/s. Address width controls how many locations can be named; data width controls how much moves at once.
A CPU's word is its natural working size, commonly 32 or 64 bits. A 64-bit processor does not require every connection to have 64 wires. Its implemented address range can also use fewer than 64 bits.
Modern links keep the same jobs
Memory channels, PCI Express and USB replace one shared bus with several links. PCI Express and USB are serial: bits travel one after another over fast wire pairs. Addresses, values and commands are packed into messages. They still identify a destination, carry contents and coordinate the transfer.
Key Takeaways
- An address identifies a location; data is the content transferred.
- Read and write commands travel as control signals.
- An n-bit address has 2ⁿ possible values; byte addressing makes the capacity 2ⁿ bytes.
- Each extra address bit doubles the address range.
- Bandwidth equals bytes per transfer multiplied by transfers per second.
- Serial links carry addressing, data and control information in messages.
1.3 Getting data into and out of a computer
An input device supplies data; an output device presents a result or acts on it. The classification describes the device's role in the system. It does not describe how complicated the device is inside.
Classify the action
Keyboards, cameras, microphones, barcode readers and sensors supply input. Screens, printers, speakers and actuators supply output. An actuator changes something physical, such as opening a valve or turning a motor.
Some devices do both. A touchscreen senses touches and displays images. A headset combines a microphone with speakers. A network adapter sends and receives data. Storage drives also perform reads and writes through I/O controllers, but their main purpose is keeping data, so they form the separate category secondary storage.
A printer can contain a processor that turns a page into printable dots. It remains an output device because of what it does for the computer. A wireless mouse supplies input just as a wired one does.
Turn continuous signals into numbers
Sound and temperature vary continuously: they are analog signals. An analog-to-digital converter (ADC) measures a signal at regular intervals and encodes the samples as numbers. A digital-to-analog converter (DAC) turns digital values into an analog output, such as the signal driving a speaker.
For one audio channel sampled 44,100 times each second with 16 bits per sample:
This is the raw sample data rate. Each second contains 44,100 measurements, and each measurement needs 16 bits. Sampling and encoding let a computer store and process the recording.
Hardware controller, software driver
Devices connect through ports or wireless links such as USB, HDMI, Bluetooth or Wi-Fi. A device controller is circuitry that handles low-level communication and exposes registers the CPU can read or write. A device driver is software that translates OS requests into commands for the device. The controller is hardware; the driver is software.
Let devices ask for attention
With polling, the processor repeatedly checks a status register. This is simple, but a device that is usually idle can cause many checks with no useful result.
With an interrupt, the controller signals when attention is needed. The CPU completes the current instruction in the simple instruction-cycle model, saves the interrupted state, and runs an interrupt handler. It then restores the saved state and continues. A key press or completed disk read can trigger this sequence.
People and many devices act far more slowly than a CPU. A person types only a few characters per second, while a processor can execute billions of instructions per second. Interrupts let the CPU work between events.
For a large transfer, direct memory access (DMA) lets a device or DMA controller move a block directly to or from RAM. The CPU sets up the operation and works on something else. A completion interrupt tells it when the block is ready. DMA removes the need for the CPU to copy every byte; it still participates in arranging and completing the transfer.
Key Takeaways
- Classify input and output by the action performed for the computer.
- An ADC encodes sampled analog input; a DAC produces analog output.
- A controller is hardware, while a driver is software.
- Polling checks repeatedly; an interrupt signals that attention is needed.
- DMA transfers blocks between a device and RAM without CPU copying of every byte.
2How a processor carries out work
Inside a processor, simple circuits combine into a machine that can follow a program. Start with gates acting on bits, then identify the registers and control signals that move an instruction through the CPU. A short trace makes the changing state visible. Clock speed, cores, caches and pipelines explain why executing the same useful work can take different amounts of time on different systems.
2.1 From switches to calculations
A computer's smallest operations come from circuits that switch between two signal levels. A high voltage represents 1 and a low voltage represents 0. These levels stand for bits; a chip does not recognize the meaning of a photo or a sentence.
Gates turn input bits into an output
A transistor acts as an electronically controlled switch. Small groups form logic gates, each with a fixed input/output rule. A truth table lists every input combination and its output. With two inputs there are four combinations; in general, inputs need rows.
NOT reverses its single input. The two-input gates behave as follows:
| A | B | AND | OR | XOR | NAND | NOR |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 | 1 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 |
AND needs both inputs to be 1. OR needs at least one, including both. XOR needs different inputs. NAND reverses AND; NOR reverses OR. Reading OR as "one but not both" confuses it with XOR.
To evaluate (A AND B) OR (NOT C) for A = 1, B = 0, C = 0, work from the inputs outward. A AND B gives 0. NOT C gives 1. Finally, 0 OR 1 gives 1. Write down the intermediate outputs so the final gate receives the correct inputs.
Gates add binary digits
A half adder takes two bits. Its sum output is XOR and its carry output is AND. For two input 1s, the sum bit is 0 and the carry bit is 1: the two-bit result is 10, meaning 2.
A full adder also accepts a carry from the preceding column. Chaining these circuits lets an ALU add longer numbers. Follow 0110 plus 0011 from the right:
- The rightmost column gives 1, with no carry.
- The next column has two 1s: write 0 and carry 1.
- The next has 1, 0 and carry 1: write 0 and carry 1.
- The leftmost has 0, 0 and carry 1: write 1.
The result is 1001, or 9. A carry belongs to the next column; dropping it changes the value.
Gates can hold a bit
Feedback means feeding a circuit's output back into its input. Cross-coupled NAND or NOR gates form a latch that holds one bit while power remains on. A flip-flop captures a new bit at a clock edge, keeping updates in step with the processor's clock. Registers use clocked storage circuits. SRAM cache cells use latch-style circuits; DRAM stores charge in capacitors.
NAND and NOR are each universal: either gate type alone can build any logic function. Connecting both NAND inputs to A gives A NAND A, which acts as NOT A.
These are layers of abstraction. Transistors build gates; gates build adders, registers and control circuits; these build a processor that executes instructions. A programmer can use the instruction layer without designing the switches underneath it.
Key Takeaways
- Truth tables enumerate every input combination.
- OR includes the case where both inputs are 1; XOR excludes it.
- Evaluate a circuit through its intermediate gate outputs.
- A half adder produces an XOR sum and an AND carry.
- Feedback stores bits; clock edges control flip-flop updates.
- NAND and NOR are each sufficient to build any logic function.
2.2 The processor’s working parts
The CPU, or processor, executes a program's instructions. Its control unit directs work, its arithmetic logic unit performs operations, and its registers hold the values needed immediately. A clock coordinates changes in these circuits.
Direct the work and perform it
The control unit fetches an instruction, decodes it and issues control signals. It might tell memory to return a value, select two inputs for the ALU and enable a register to store the result. It coordinates the operation; the ALU does the arithmetic or logic.
ALU operations include addition, subtraction, comparisons, bit shifts and gates such as AND and XOR. Results also update status flags. A zero flag indicates a zero result; a negative flag records a negative result. A branch can test a flag to choose the next instruction.
Registers hold the immediate working state
Registers are very small, fast storage locations inside the processor. A general-purpose register usually holds one word. For example, x86-64 provides 16 general-purpose integer registers, and 64-bit ARM provides 31. Programs use them to keep values close to the ALU.
The textbook processor makes the following roles visible:
| Register | Role |
|---|---|
| Program counter, PC | Address of the next instruction to fetch |
| Memory address register, MAR | Address for the next memory read or write |
| Memory data register, MDR | Value just read or about to be written |
| Current instruction register, CIR | Instruction being decoded and executed |
| Accumulator, ACC | Working value and ALU result in the teaching machine |
MDR is also called the memory buffer register (MBR). CIR is also called the instruction register (IR). Actual chips organize these jobs in more complex ways, but the model lets you follow the movement of an instruction and its data.
The PC holds an address, not a total of instructions completed. A jump can send it backward to repeat a loop. MAR and MDR also differ: an address such as 10 goes into MAR; the value stored at address 10 goes into MDR.
A clock cycle is one timing step
Clock speed counts pulses per second, measured in hertz (Hz). A 3 GHz clock produces 3 billion cycles each second. The duration of one cycle is:
A pulse lets parts of a circuit advance. Some instructions need several timing steps, and modern processors overlap work on several instructions.
More than one processing core
A core has the control, arithmetic, register and cache resources needed to run an instruction stream. Four cores can carry out four streams at once. A program benefits when its work can be divided among them; merely owning four cores does not split every task.
A GPU has many smaller processing units suited to performing similar operations on many data items. Drawing pixels, processing video and some machine-learning calculations have this form. A CPU suits a wider mix of instructions and decisions.
Think of a kitchen: the control unit assigns actions, the ALU performs them, registers hold ingredients at hand, and memory supplies more. The CPU follows bit patterns mechanically; the useful meaning comes from the program.
Key Takeaways
- The control unit coordinates operations; the ALU performs arithmetic and logic.
- Flags record conditions such as a zero result for later branches.
- PC, MAR, MDR, CIR and ACC hold different parts of the current working state.
- A clock cycle is a timing step, not necessarily a completed instruction.
- Multiple cores help work that can run in parallel.
2.3 Follow an instruction through the CPU
The fetch-decode-execute cycle connects the processor's parts into a running program. Each cycle brings in an instruction, determines its operation and carries it out. A trace records the changing registers and memory so each result has a visible cause.
Fetch the instruction
In the simple processor, fetch follows this sequence:
- Copy the PC into the MAR.
- Put the address on the address bus and send a memory-read signal.
- Receive the instruction over the data bus into the MDR.
- Copy it into the CIR.
- Advance the PC to the next instruction.
In the teaching machine each instruction occupies one location, so the PC increases by 1. A byte-addressed processor advances by the instruction's byte length. During execution the PC already points beyond the fetched instruction.
Decode, then execute
The control unit separates the opcode, which specifies the operation, from the operand, which supplies a value, register or address. It then sends the signals needed to execute the instruction. A load reads data, an add uses the ALU, a store writes data, and a jump changes the PC. Some descriptions call writing the result a separate write-back stage.
Trace a complete program
The teaching machine has one accumulator. Here LOAD, ADD and STORE use memory addresses as operands.
Address Instruction Data address Value
0 LOAD 10 10 7
1 ADD 11 11 5
2 STORE 12 12 0
3 HALT
Start with PC 0. Fetching LOAD 10 moves the PC to 1. Execution puts address 10 in MAR, reads 7 through MDR, and sets ACC to 7. The operand 10 names a location; it is not the value loaded.
Next, ADD 11 is fetched and PC becomes 2. Memory location 11 supplies 5. The ALU adds 7 and 5, leaving ACC 12. Fetching STORE 12 advances PC to 3. Execution places address 12 in MAR and value 12 in MDR, then writes 12 to that location. ACC remains 12. Finally, fetching HALT advances PC to 4 and execution stops the teaching machine. Four instructions have run.
Branches replace the next address
JUMP 0 puts 0 into PC during execution, regardless of its previous value. JUMPZ 6 jumps only when ACC is zero. If that instruction was fetched from address 4, fetch first makes PC 5. Execution then sets PC to 6 when ACC is zero; otherwise PC stays 5. This is how a sequence can choose a route or repeat a loop.
Interruptions and real processors
At an instruction boundary in this model, the CPU checks for interrupts. To handle one, it saves the PC and other working registers, runs the handler, then restores the saved state. The interrupted program resumes with its own values and next address.
A CPU does not fetch a whole source program at once. It executes machine instructions, often several for one source statement. Modern CPUs overlap and reorder internal work while preserving the program's required results.
Key Takeaways
- Fetch reads the instruction through MAR and MDR into CIR.
- PC advances during fetch; execution of a jump can replace that address.
- An address operand must be used to read the value stored there.
- STORE writes ACC to memory without changing ACC in this teaching machine.
- Interrupt handling saves and restores the interrupted working state.
- Real processors overlap work while preserving the required program results.
2.4 Why a program finishes sooner
Processor performance depends on the work a program needs and how quickly the computer completes that work. Clock speed, useful work per cycle, waiting time and opportunities for parallel work all matter.
Clock speed and a fixed cycle count
For a task requiring a known number of clock cycles:
A task needing 6 billion cycles takes 2 seconds at 3 GHz and 1.5 seconds at 4 GHz. The comparison holds the cycle count fixed. Across different processor designs, a program may need different numbers of cycles. A 3.5 GHz chip can therefore outperform a 4 GHz chip by finishing more useful instructions per cycle.
Higher clock rates also use more power and produce heat. Thermal throttling reduces the clock when a processor gets too hot. This helps explain why performance gains have come from more than raising gigahertz.
Cores divide only the parallel part
Suppose a task takes 10 seconds on one core. Two seconds must happen in sequence; eight seconds can be divided evenly among four cores. Ignoring coordination overhead:
Dividing the whole 10 seconds by four gives 2.5 seconds, but incorrectly divides the sequential work. Even unlimited cores cannot remove those two seconds. Multiple cores also help separate programs run at the same time, even when each program uses only one core.
A pipeline overlaps stages
In a three-stage pipeline, one instruction executes while the next decodes and another fetches. Each instruction still passes through all three stages. The gain is more instructions completed over a period of time.
If each stage takes one cycle, ten independent instructions take 30 cycles without overlap. An ideal pipeline needs three cycles to finish the first instruction and one more for each remaining instruction:
A branch can make instructions already fetched useless. Discarding that work costs cycles, so processors predict branches. Real dependencies and memory waits also keep a pipeline from always reaching its ideal rate.
Keep the processor supplied
A cache holds nearby copies of instructions and data. More useful cache capacity can reduce trips to RAM, especially when a program repeatedly uses a working set that did not fit before. If that working set already fits, extra capacity may help little.
Memory bandwidth limits how fast many values can arrive. Storage speed matters when opening files or starting applications: moving from a hard disk to an SSD can reduce the delay even though the CPU is unchanged. Word size and the instructions a processor supports also affect suitable workloads.
More transistors, different uses
Moore's law describes Gordon Moore's observation, first made in 1965 and revised in 1975, that transistor counts doubled about every two years. This historical trend is not a rule that programs become twice as fast on a fixed schedule. As scaling has slowed, chip designers have used additional transistors for cores, caches, GPUs and specialized accelerators. A useful comparison asks how long the same task takes under the same conditions.
Key Takeaways
- Compare execution time for the actual task, not clock speed alone.
- More cores reduce only work that can be divided among them.
- Pipelining raises throughput by overlapping instruction stages.
- Cache, memory bandwidth, storage and heat can limit useful CPU work.
3How written programs become machine instructions
A readable program and the instructions a CPU executes are different forms of the same intended work. Assembly exposes individual operations and branches; compilers and interpreters connect high-level code to those operations. Following a build shows why a source file differs from an executable, why libraries matter, and why moving software to another platform may require a new build or a suitable runtime.
3.1 Reading the instructions a processor runs
Machine code is binary instructions for a particular kind of processor. Assembly language writes those instructions with readable names. Both describe operations much closer to the hardware than a high-level language such as Python or C.
Operations and operands
An instruction contains an opcode specifying what to do and usually one or more operands specifying what to use. An operand can name a register or memory address, or supply a value directly. Its meaning comes from the instruction's defined format.
Consider an 8-bit teaching encoding. The first four bits hold an opcode; the last four hold an address. If LOAD is 0001, then LOAD 10 becomes 0001 1010, because decimal 10 is binary 1010. Four opcode bits allow operation codes. Four address bits name locations 0 through 15. This encoding illustrates a limited format; the other teaching-machine traces use written instructions with larger addresses.
An instruction set architecture (ISA) defines the instructions, encodings and registers a processor offers. x86-64, ARM and RISC-V are examples. ARM's A64 instructions are 32 bits long; x86-64 instructions range from 1 to 15 bytes. A 64-bit processor's word size does not determine every instruction's length.
A readable loop
An assembler turns assembly mnemonics and labels into machine code for an ISA. Useful instruction groups include data transfer, arithmetic and logic, control flow, and system or I/O operations.
This accumulator program counts down from 3. SUB 21 subtracts the contents of address 21. JUMPZ branches if ACC is zero.
0 LOAD 20
1 SUB 21
2 STORE 20
3 JUMPZ 5
4 JUMP 0
5 HALT
20 holds 3; 21 holds 1.
On the first pass, LOAD reads 3, SUB leaves 2, and STORE saves 2. The zero test fails, so JUMP 0 starts another pass. The second pass saves 1 and jumps back. The third saves 0, so JUMPZ 5 goes to HALT.
The first two passes use five instructions each. The last uses four before HALT, which also counts as an instruction: . Counting only the six written lines misses repeated executions.
One source statement, several instructions
A high-level statement such as total = price + tax can become operations to load a value, add another and store the result. High-level languages express variables, choices, loops and functions without naming every register. Assembly usually maps each written instruction to one machine instruction and depends closely on its ISA.
Machine code for x86-64 cannot execute natively as ARM code. The source can be recompiled for ARM, or a translation or emulation layer can handle the mismatch.
RISC and CISC
RISC designs such as ARM and RISC-V favor simple, regular instructions. Many use fixed-length instructions, but RISC-V can mix 16-bit compressed forms with standard 32-bit instructions. CISC designs such as x86 offer more complex, variable-length instructions. Modern x86 processors break instructions into simpler internal operations. These labels describe design approaches, not a guarantee that one machine is faster.
Key Takeaways
- An opcode selects an operation; operands specify its inputs or destinations.
- An ISA defines the machine-code contract a processor implements.
- An assembler translates readable mnemonics into machine code.
- Loops execute some instructions repeatedly, so execution counts differ from line counts.
- High-level programs need translation or an interpreter implemented in machine code.
- RISC and CISC describe instruction-set styles, with exceptions to simple length rules.
3.2 From source code to a running program
Source code is readable program text. A processor executes machine instructions, so a tool must bridge the gap. Compilation and interpretation describe ways to do that; many real implementations combine them.
The translation tools
| Tool | Its work |
|---|---|
| Assembler | Translates assembly into machine code |
| Compiler | Translates code into another form, often machine code or bytecode |
| Interpreter | Carries out a program's operations while it runs |
Most compilers work before a program starts. A just-in-time (JIT) compiler works during execution. An interpreter is itself a machine-code program: the CPU executes the interpreter, which performs the source program's operations.
Follow a C build
The command clang hello.c -o hello builds an executable named hello from hello.c. A build tool such as make can arrange compiler commands for the programmer. The main stages are:
- Preprocessing: handle directives such as
#include <stdio.h>, bringing header declarations into the source. - Compiling: translate the C code into assembly-level operations.
- Assembling: encode those operations as machine code in object files.
- Linking: connect object code and library references to produce an executable.
Headers describe library interfaces; including a header does not by itself copy the compiled library implementation into the program. Linking supplies the connection to that code. Static linking copies required library code into the executable. Dynamic linking records shared-library dependencies that are loaded and connected when needed.
The executable targets an ISA and an operating-system format. Building for an ARM Mac and an x86-64 Windows computer therefore requires separate native builds. Editing the source also requires rebuilding a compiled executable before the change takes effect.
Errors happen at different stages
A compiler can report syntax errors, such as a missing semicolon in C, and type errors where the language checks types. Successful compilation does not establish that the program solves the right problem. A logic error produces a wrong result. A run-time error occurs while the program executes, such as division by an input value that turns out to be zero.
A simple interpreter may reach an error only after earlier statements have run. Python checks an entire file's syntax first, but an undefined name can still fail only when execution reaches it. The translation method alone does not tell you when every kind of error is found.
Bytecode and virtual machines
Java compiles source into bytecode, instructions for the Java Virtual Machine (JVM). Each supported platform supplies its own JVM. It can interpret bytecode and JIT-compile frequently used sections into the local CPU's machine code. The bytecode stays portable because the platform-specific JVM handles the hardware differences.
CPython also compiles Python into bytecode and executes it with a virtual machine. PyPy uses a JIT compiler, and browser JavaScript engines use JIT compilation too. "Compiled" and "interpreted" describe implementations, not permanent properties of a language.
Ahead-of-time native code usually avoids repeated interpretation work. Interpretation makes an edit-and-run cycle convenient, while bytecode and JIT combine portability with runtime optimization. In every route, the CPU ultimately follows machine instructions, and the OS loads the required executable code into memory.
Key Takeaways
- Compilers translate code; interpreters carry out operations during execution.
- A C build involves preprocessing, compilation, assembly and linking.
- Static linking includes library code; dynamic linking records shared-library dependencies.
- Compilation can catch syntax errors while leaving logic and run-time errors.
- Bytecode runs through a platform-specific virtual machine.
- JIT compilation translates during execution; languages can have different implementations.
- Native executables depend on both an ISA and an operating-system format.
4Memory, storage and fast copies
The place where a computer keeps data affects both whether it survives power loss and how quickly it can be used. Compare working RAM with persistent drives, then follow the hierarchy from registers to archives. Storage choices depend on access patterns as well as capacity. Caching explains how a small, fast store can save many slow trips, and a weighted average shows how strongly misses affect the result.
4.1 Working memory and its addresses
Main memory holds the instructions and data currently available to the CPU. For an ordinary application stored on an SSD, the OS first brings the needed code and data into RAM. The CPU then fetches instructions through its memory and cache system.
RAM, DRAM and SRAM
RAM means random-access memory: a location can be reached without going through all earlier locations. Normal working RAM is volatile, so its contents are lost without power. Saving a document copies its data to non-volatile storage.
Main memory uses DRAM, which stores bits as charge in small capacitors. The charge leaks, so the cells need refresh, commonly over a 64 ms refresh interval. SRAM uses latch-style transistor circuits that retain their state while powered. It needs no refresh, but uses more space and costs more per bit. Its speed suits processor caches.
| Kind | Holds a bit using | Typical role | Keeps contents without power? |
|---|---|---|---|
| DRAM | Charge in a capacitor | Main working memory | No |
| SRAM | A latch-style circuit | CPU cache | No |
| Firmware flash | Trapped charge | Startup instructions | Yes |
ROM, or read-only memory, is non-volatile memory associated with fixed instructions such as firmware. Modern UEFI or BIOS firmware normally lives in updateable flash. A phone's advertised file capacity is flash storage, even when a description informally calls it "ROM"; the phone routinely writes files there.
A byte has an address
In byte-addressable memory, each address names one byte. A 4-byte integer starting at decimal address 1000 occupies locations 1000, 1001, 1002 and 1003. The next unused location is 1004. Addresses are often written in hexadecimal, such as 0x7FFE0010, because hex compactly represents bit patterns.
The address identifies where bytes are found. Reading the number written as an address is different from reading the value stored at that address.
Capacity units use two systems
A byte contains 8 bits. Lowercase b means bits; uppercase B means bytes.
| Decimal unit | Bytes | Binary unit | Bytes |
|---|---|---|---|
| kB | 1,000 | KiB | 1,024 |
| MB | 1,000,000 | MiB | 1,048,576 |
| GB | 1,000,000,000 | GiB | 1,073,741,824 |
| TB | 1,000,000,000,000 | — | — |
A drive sold as 1 TB contains bytes. In GiB the count is:
Some operating-system displays label this binary count "GB." The different number follows from the unit size; it is not evidence of missing space.
Capacity is different from processor speed
More RAM lets more running programs and data stay ready at once. When working data exceeds RAM, the OS may move pages to storage, making access slower. Extra RAM helps that shortage but does not raise the CPU's clock speed. Deleting saved files frees storage. Closing unneeded programs or tabs can release working RAM.
Key Takeaways
- Working RAM is volatile; saving transfers data to non-volatile storage.
- DRAM requires refresh; SRAM uses latch circuits and suits fast caches.
- Firmware persists without power and can live in updateable flash.
- Each address in byte-addressable memory names one byte.
- Decimal GB and binary GiB use different numbers of bytes.
4.2 Choosing storage for the job
Secondary storage keeps programs and files without power. Compared with RAM it offers more capacity at a lower cost per byte, with slower access. Different storage technologies trade speed, cost, portability and durability.
Magnetic disks and solid-state drives
A hard disk drive (HDD) stores magnetic patterns on spinning platters. A moving head seeks the right track, then waits for the desired part of the platter to rotate beneath it. Both movements add access delay.
At 7,200 revolutions per minute, one turn takes:
The average rotational wait is half a turn, about 4.2 ms. This is only the rotational part, not the full read time; seeking and transferring also take time. Moving parts also make a working HDD vulnerable to shocks.
An SSD stores charge in flash cells and has no moving parts. Small random reads take tens of microseconds instead of the milliseconds typical of HDD access. SSDs are quiet, resist shocks and suit portable computers. HDDs generally offer a lower cost per terabyte for large collections.
Flash cells tolerate a limited number of erase/write cycles. The controller uses wear leveling to spread writes across cells. USB flash drives, memory cards and phone storage also use flash, though the controller and interface affect their performance.
Optical discs and tape
| Medium | How it stores or reads data | Useful setting |
|---|---|---|
| CD, DVD, Blu-ray | A laser reads marks on a reflective layer | Distributing media or storing a disc archive |
| Magnetic tape | Data follows a sequence along a long tape | Large backups and archives |
Typical capacities are about 700 MB for a CD, 4.7 GB for a single-layer DVD and 25 GB for a single-layer Blu-ray disc. Optical media are portable but slow compared with modern drives.
Tape offers low cost for large archives. Its sequential access means the drive must wind to reach a distant file. Disks and SSDs provide direct access, reaching a selected location without traversing all earlier data. Tape therefore suits scheduled bulk backups better than an application that repeatedly opens scattered small files.
Cloud storage is a service
Cloud storage keeps files on equipment in a provider's data centers. The underlying media are still SSDs, HDDs or tape. A network connection adds access and transfer delays. The service offers sharing, remote access and off-site copies, with ongoing fees and dependence on the provider's access controls and reliability.
Match the limiting factor
Access time is the delay before data starts arriving. Transfer rate measures how quickly it flows afterward. Many small file reads repeatedly pay access delay; one large continuous file puts more emphasis on transfer rate.
An SSD suits a laptop's active programs. HDDs suit a server storing 20 TB of video economically. Tape or a cloud archive suits a company's long-term records, while a USB drive is convenient for carrying files. Choose using capacity, access time, transfer rate, cost per byte, power use, reliability and portability. Being made from chips does not make an SSD into working RAM: it remains non-volatile storage behind a storage controller.
Key Takeaways
- HDD access includes seek and rotational delay; SSDs have no moving parts.
- Wear leveling spreads flash writes across cells.
- Tape provides sequential access and suits large archives.
- Cloud storage uses physical storage reached over a network.
- Access time and transfer rate measure different parts of a read.
- Choose storage by the task’s access pattern and practical needs.
4.3 Keeping useful data close to the CPU
A computer combines several kinds of storage because fast access, large capacity and low cost do not come together in one technology. The memory hierarchy puts a small amount of very fast storage near the CPU and larger, slower stores farther away.
The levels of the hierarchy
From fastest and smallest toward slower and larger, the main levels are registers, L1/L2/L3 cache, RAM, SSD, HDD, and archive storage. Cost per byte generally falls as capacity grows.
| Level | Illustrative access time | Typical scale |
|---|---|---|
| Registers | Fraction of a nanosecond | A few kilobytes or less |
| L1 cache | About 1 ns | Tens to hundreds of kilobytes per core |
| L2 cache | A few ns | Up to a few megabytes |
| L3 cache | About 10–20 ns | Several to tens of megabytes |
| RAM | About 50–100 ns | Several to tens of gigabytes |
| SSD | About 20–100 µs | Hundreds of gigabytes to terabytes |
| HDD | About 5–10 ms | Several terabytes |
These times show scale, not one fixed specification for every device. Using 1 ns for L1, 100 ns for RAM and 10 ms for a disk, RAM takes about 100 times as long as L1 and the disk about 100,000 times as long as RAM.
Hits, misses and useful copies
A CPU cache uses SRAM to hold blocks copied from main memory. Hardware looks through the cache levels before fetching from RAM. A hit finds the requested contents in the cache. A miss requires a slower-level fetch and can bring a copy into the cache.
The hit rate is hits divided by all accesses. For 950 hits in 1,000 accesses, it is 95%. A miss is not missing or damaged data; it means the fast copy was not available.
Why past access predicts future access
Temporal locality means recently used contents are likely to be used again soon. A loop repeatedly reads a counter and its own instructions. Spatial locality means nearby addresses are likely to be used soon. Reading consecutive list elements has this pattern.
A cache brings in a whole cache line, commonly 64 neighboring bytes, taking advantage of spatial locality. Several levels balance capacity with lookup time: one enormous cache would take longer to search.
Compute the average delay
Suppose a cache check takes 1 ns and a RAM access takes 100 ns. A miss costs both, so it takes 101 ns. At a 95% hit rate:
At an 80% hit rate:
The second average is times as large. Weight the full hit cost and full miss cost by how often each occurs. Forgetting the cache check on a miss would change this model's answer.
Caching beyond the processor
The OS caches file contents in RAM. A browser caches downloaded web files on storage, and content delivery networks keep copies near users. They all reuse nearby copies to avoid repeated slow retrieval. Clearing a browser cache removes browser files; it does not clear CPU cache circuits. CPU caches hold small memory blocks, not an organized library of whole documents.
Key Takeaways
- The hierarchy trades speed and cost per byte against capacity.
- A cache hit finds a fast copy; a miss fetches from a slower level.
- Temporal locality reuses contents; spatial locality uses nearby addresses.
- Average access time weights the complete cost of hits and misses.
- Browser, file and CPU caches use the same broad idea at different layers.
5How the operating system puts the parts to work
Opening an application depends on more than a processor and a program file. The operating system assigns memory, shares processor time, checks permissions and offers file and device services. Follow startup from firmware to kernel, then follow a running editor through its memory regions, input events and a save request. Virtual memory connects each process’s view of addresses to the physical RAM it is allowed to use.
5.1 The operating system’s everyday jobs
An operating system (OS) manages hardware and supplies services to applications. Windows, macOS and Linux serve personal computers and servers; Android and iOS serve mobile devices. The visible desktop is only one part of this work.
Manage resources and hide hardware details
As a resource manager, the OS assigns processor time, working memory, files and devices to programs and users. As an abstraction, it provides simpler operations that hide hardware details. A text editor can request "open the file report.txt" without choosing disk tracks or device commands.
| Function | What the OS does |
|---|---|
| Process management | Starts, schedules and ends running programs |
| Memory management | Assigns memory and enforces separation |
| File management | Organizes files, folders and stored data |
| Device management | Communicates with devices through drivers |
| Security | Enforces accounts and permissions |
| Networking | Supplies services for exchanging data |
The user interface lets people request this work. A graphical user interface (GUI) uses windows, icons, menus and touch or a pointer. A command-line interface (CLI) accepts typed commands. Commands such as ls on Linux and macOS or dir on Windows list files; scripts can combine commands for repeated tasks.
The kernel controls privileged operations
The kernel is the OS core responsible for hardware control and protected resources. Applications run in user mode with restricted privileges. Kernel code runs in kernel mode with greater privileges. An application requests a protected service through a system call, such as asking the OS to read a file.
The kernel checks permissions and carries out the permitted action. A faulty application cannot simply use a normal user-mode instruction to take control of every device or read another process's protected memory.
Share processor time
The scheduler decides which ready program gets processor time. Short turns on a single processing stream make music playback and document editing appear simultaneous. Multiple cores also allow work to run at the same moment. Some CPUs support hardware multithreading within a core, but time sharing remains necessary when more work is ready than the hardware can execute together.
Give files names and devices drivers
A file system tracks file contents and metadata such as size, dates and permissions. Folders form a hierarchy; a path identifies a file, for example /home/sam/notes.txt on Linux. NTFS, APFS and ext4 are file-system examples.
Deleting a file commonly removes its directory entry and releases its space for reuse. That differs from deliberately overwriting every byte. Old data can sometimes remain recoverable, especially on HDDs; a normal delete is not a secure-erasure guarantee.
A driver translates general device requests into commands a controller understands. Standard drivers handle many keyboards and USB drives, while some devices require a specific driver.
Match software to its role
The OS, drivers and utilities such as backup tools are system software. Browsers, editors, games and spreadsheets are application software. Mobile systems emphasize battery life, touch and app separation; servers support network services. A real-time OS meets specified response deadlines for control tasks. Very simple embedded devices can run one program without a full OS.
Key Takeaways
- The OS manages shared resources and hides hardware details behind services.
- System calls request kernel services from restricted user-mode applications.
- The scheduler shares processor time among ready work.
- File systems track file contents, names, paths and permissions.
- Drivers connect general OS requests to device-specific commands.
- System software runs and maintains the computer; applications perform user tasks.
5.2 From power-on to a saved document
Starting a computer and starting an application involve different stages. Startup brings the operating system into control. Application loading then creates a running process that uses the processor, memory and OS services.
Start with persistent instructions
At power-on, working RAM has no usable running program. The CPU begins with firmware stored in non-volatile memory. On a modern PC, UEFI firmware prepares hardware and performs startup checks, often called the power-on self-test (POST). It selects a boot device and starts a bootloader. The bootloader loads the OS kernel into RAM and transfers control to it. The kernel prepares memory management, drivers and services before the login or home screen appears.
Turn a program file into a process
A program is stored instructions. A process is a running instance, with memory, register state and resources. Separate instances of one editor can keep separate documents even though they started from the same program file.
To launch an application, the OS checks the executable and permission to run it, creates an address space, loads the initially needed code and data, sets up a stack and arranges its starting instruction address. More pages can be loaded when used. The scheduler gives the process time on the CPU, which executes its machine instructions.
Different regions hold different contents
| Region | Contents |
|---|---|
| Code | Machine instructions |
| Data | Global variables |
| Heap | Memory requested while the program runs |
| Stack | Active function calls, local values and return addresses |
Calling a function adds stack information; returning releases that call's part. Repeated calls with no stopping point can exhaust the stack, causing a stack overflow. A memory leak happens when a program keeps memory it no longer needs, causing its retained allocation to grow. Simply using a large amount of memory is not enough to diagnose a leak.
Separate addresses from physical locations
Virtual memory gives each process its own address space. The OS and the CPU's memory management unit (MMU) map virtual addresses to physical RAM in pages, often 4 KiB. Two processes can use 0x1000 for different physical locations. Access permissions stop unauthorized reads or writes; the OS can also explicitly allow shared pages.
A prohibited access causes a fault, which can end the process. On Linux or macOS, a C program may report a "segmentation fault." A virtual address names a location in that process's map, not necessarily an identical numbered byte of RAM.
When memory demand is high, the OS can move inactive pages to a swap or page file on storage. Retrieving an illustrative page in 100 µs takes about 1,000 times a 100 ns RAM access. Repeated page movement, called thrashing, can dominate execution time. Reducing active memory demand or adding RAM can help.
Follow a key press through the layers
A keyboard controller signals an interrupt. The OS handler and driver obtain the event and deliver it to the editor process. The editor updates the document in its memory and asks OS graphics services to update the display. Saving asks the file system to write the document to storage. When the process ends, the OS reclaims its memory and resources. Saved data remains; changes kept only in process memory disappear.
Key Takeaways
- Firmware starts before the bootloader loads the kernel.
- A process is a running program instance with its own state.
- Code, data, heap and stack hold different parts of a process.
- Virtual memory maps process addresses to RAM and enforces access permissions.
- Swapping uses storage for pages; frequent transfers can cause thrashing.
- Editing changes working memory; saving writes the document to storage.
- The OS reclaims process resources when the process ends.
How Computers Work examples
1Trace the paths inside a computer
13 steps
- 1IntroductionFollow a simple action
Opening a photo involves several parts: input requests the action, storage keeps the file, RAM holds working contents, and the processor follows instructions to display it. Instructions share memory with data, the von Neumann design, so one machine can do many jobs.
We will separate those jobs, trace one memory transfer, and see how devices get attention (an interrupt) without keeping the CPU waiting. These roles also describe a phone or a controller inside a larger device.
- 2ExplanationLocate the working parts
The CPU executes instructions. RAM holds the current instructions and data; an SSD or HDD holds persistent files. Input devices supply data, and output devices present results or act on them.
The motherboard connects these parts. A phone combines many functions in a system on a chip. The complete computer case is not the CPU: the processor is one component inside the system.
- 3Key InsightPrograms are memory contents
In the von Neumann design, one main memory holds instructions and data. The CPU fetches binary instructions from it, allowing a new loaded program to give the same hardware a different task.
A bit pattern has no built-in meaning to memory. The byte
01000001could represent 65, the ASCII letter "A", or part of an instruction. Its use supplies the interpretation. - 4ChallengeChange the job
A temperature controller and a laptop both contain processors, memory and input/output. Why is the controller an embedded system, and what lets the laptop change from editing text to playing audio?
---reveal---
The controller performs a dedicated job inside another device. The laptop changes tasks by running different stored instructions. The hardware roles stay the same while the program changes the work they perform.
- 5AnalogyChoose a mailbox, then its contents
Think of memory locations as numbered mailboxes. The address selects a mailbox; the data is what it contains. A read requests its contents, and a write replaces them.
In the classic system bus, the address bus selects the location, the data bus carries contents, and the control bus carries the read or write command. Changing contents never renumbers the location.
- 6ExampleRead address 200
The CPU wants the contents of memory address 200. It sends 200 on the address bus and asserts a read command on the control bus.
Memory finds that location and places its contents, here 7, on the data bus. The CPU receives 7 into a register. The address made the selection; the returned data supplies the value. No write occurs, so the contents of location 200 remain 7.
- 7ExplanationCount locations and transfers
With 16 address bits, byte-addressable memory has 65,536 locations, or 64 KiB. Adding one address bit doubles that range.
Data width answers a different question. A 64-bit path moves 8 bytes per transfer. At a billion transfers per second its bandwidth is 8 GB/s. More address bits let you name more locations; more data bits let you move more contents in a transfer.
- 8ChallengeSeparate the two widths
A byte-addressable teaching system has 11 address bits and a 16-bit data path. How much memory can it address, and how many bytes move in a transfer?
---reveal---
It can address bytes, or 2 KiB. The data path carries 2 bytes per transfer because each byte has 8 bits. Multiplying the address count by two would wrongly assume each address names two bytes.
- 9ExplanationTranslate between signals and values
A microphone supplies input, and a speaker provides output. Sound varies continuously, while a computer keeps digital values. An ADC samples input and encodes measurements as numbers; a DAC converts digital output values into an analog signal.
A touchscreen performs two roles: sensing touches supplies input and displaying an image supplies output. A device can contain processing circuitry and still be classified by that role.
- 10ConnectionController and driver work together
A controller is hardware that communicates with a device. A driver is software that turns OS requests into commands for that controller.
Polling repeatedly asks whether the device is ready. With an interrupt, the controller signals when attention is needed. For a large block, DMA can move contents between the device and RAM while the CPU works elsewhere, then signal completion.
- 11ChallengeAvoid empty checks
A scanner sends a large image to RAM. The CPU sets up the transfer, continues another task and receives a completion signal. What do DMA and the interrupt each contribute?
---reveal---
DMA moves the image block without CPU copying of each byte. The interrupt announces that the transfer is complete so the OS can handle it. The CPU still arranges the transfer; it simply avoids doing all the byte-moving work itself.
- 12ChallengeConnect a reading to a result
A greenhouse controller reads a digital temperature value into RAM, computes a decision and opens a valve. Which are its input and output, and what must pass between memory and the CPU?
---reveal---
The temperature reading is input, and valve actuation is output. The CPU needs both the stored control instructions and the reading from memory. Addressing selects those locations, data transfer carries their contents, and control signals coordinate access.
- 13RecapRead the whole path
Identify the role first: input, processing, working memory, persistent storage or output. Then distinguish the location being selected from the contents being moved.
Stored instructions tell the CPU what to do; buses or modern links carry addressing, values and commands. Controllers and drivers connect devices, while interrupts and DMA let slow or bulky device work share a fast computer efficiently.
2Build and trace a processor operation
19 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionMake execution visible
- 2ExplanationRead a gate rule
- 3ExampleBuild a carry
- 4ChallengeEvaluate the intermediate outputs
- 5ConnectionKeep a result between steps
- 6ExplanationAssign the processor jobs
- 7ChallengeKeep address and contents apart
- 8ExplanationFetch before using the instruction
- 9ExampleFirst instruction: load
- 10ExampleSecond instruction: add
- 11ExampleThird and fourth: store and halt
- 12ChallengeTake or skip a branch
- 13Key InsightResume after an interrupt
- 14ExampleCompare a fixed cycle count
- 15ExampleDivide only the parallel work
- 16ExplanationOverlap stages, not meanings
- 17ChallengeEstimate a new parallel task
- 18ChallengeExplain an unused fast pipeline
- 19RecapConnect bits, state and time
3Follow a program from text to execution
13 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionSeparate the program’s forms
- 2ExplanationSplit an instruction into fields
- 3ExplanationName the hardware contract
- 4ExampleSet up a countdown
- 5ExampleCount executions, including the exit
- 6ChallengeChange the start, trace the exit
- 7ExplanationBuild before running
- 8ConnectionDecide where library code lives
- 9ChallengeExplain a successful build with wrong output
- 10Key InsightInterpretation still runs machine code
- 11ChallengeMove the program to another CPU
- 12ChallengeTrace two routes to the same hardware
- 13RecapKeep each layer’s job clear
4Compare memory and calculate cache effects
14 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionAsk two questions about stored data
- 2ExplanationSeparate working and persistent contents
- 3ExampleRead the capacity unit
- 4ChallengeLocate the final byte
- 5ExplanationSeparate waiting from flowing
- 6ExampleFind one part of a disk delay
- 7ChallengeMatch the storage behavior
- 8ExplanationMove down the hierarchy
- 9ConnectionPredict the next useful bytes
- 10ExampleInclude both parts of a miss
- 11ExampleChange the hit rate
- 12ChallengeCalculate a new cache average
- 13ChallengeChoose the relevant improvement
- 14RecapMatch the resource to the need
5Follow startup, a key press and a save
15 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionFollow an editor through the system
- 2ExplanationRequest a service
- 3ExampleShare execution time
- 4ChallengeIdentify the OS boundary
- 5ExplanationStart before the operating system
- 6ExampleCreate the running instance
- 7ExplanationGive memory regions different jobs
- 8AnalogyUse a private address map
- 9ChallengeKeep matching addresses separate
- 10Key InsightStorage can back memory, slowly
- 11ExampleDeliver the key event
- 12ExampleSave beyond the process lifetime
- 13ChallengeSeparate two kinds of slowdown
- 14ChallengeJoin process protection and saving
- 15RecapTrace the services in order
How Computers Work practice questions
Set 1: Connections, translation and memory choices10 Practice Questions
Question 1 of 10
Show answerHide answer
Question 2 of 10
Show answerHide answer
Question 3 of 10
JUMPZ 18 is fetched from address 7 while ACC is 4. What address is fetched next?Show answerHide answer
Question 4 of 10
Show answerHide answer
Question 5 of 10
0010. How is ADD 13 encoded?Show answerHide answer
1101, so the instruction is 0010 1101. Reversing the fields changes the operation as well as the operand. The operand is an address here; encoding it does not require knowing the contents stored at address 13.Question 6 of 10
Show answerHide answer
Question 7 of 10
Show answerHide answer
Question 8 of 10
Show answerHide answer
Question 9 of 10
Show answerHide answer
Question 10 of 10
Show answerHide answer
Set 2: Parts, instructions and everyday computer work10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
LOAD 30 and address 30 holds 14. PC starts at 8. What are PC and ACC after this instruction executes?Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
LOAD, ADD and other assembly mnemonics into binary instructions. What kind of tool is it?Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
0x3000 for private data. One stores 9 there and the other stores 22. Why can both values remain intact?Show answerHide answer
Save this lesson to see this answer.
Set 3: Tracing choices and comparing performance10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
LOAD 50, SUB 51, JUMPZ 4, ADD 51, STORE 52, HALT at addresses 0–5. Locations 50 and 51 both hold 6. What is stored at 52 when it halts?Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
(A XOR B) AND (NOT C) when A = 1, B = 1 and C = 0?Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
LOAD 40, SUB 41, STORE 40, JUMPZ 5, JUMP 0, HALT at addresses 0–5. Location 40 starts at 2 and location 41 holds 1. Starting at PC 0, how many instructions execute through HALT?Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Set 4: Diagnosing computer-system behavior10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Set 5: Connecting instructions, memory and the operating system10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
LOAD 19?Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Stuck on your own question? Homework Help
Key Terms
A
Access time and transfer rate
Accumulator
Address bus
Analog-to-digital converter
AND gate
Arithmetic logic unit
Assembler
Assembly language
B
Bandwidth
Bootloader
Branch
Bus
Byte-addressable memory
Bytecode
C
Cache
Cache hit and miss
Cache line
Clock cycle
Clock speed
Cloud storage
Compiler
Control bus
Control unit
Core
Current instruction register
D
Data bus
Device controller
Device driver
Digital-to-analog converter
Direct memory access
DRAM
E
Embedded system
Executable
F
Fetch-decode-execute cycle
File system
/home/sam/notes.txt identifies a Linux file without revealing which storage blocks contain it.Firmware
Flip-flop
G
Graphics processing unit
GUI and CLI
ls in a command line to request its file listing.H
Half adder
10.Hard disk drive
Hardware
Harvard architecture
Heap
Hit rate
I
Input device
Instruction set architecture
Interpreter
Interrupt
Interrupt handler
J
Just-in-time compilation
K
Kernel
L
Latch
Linker
Logic gate
M
Machine code
Magnetic tape
Memory address register
Memory data register
Memory hierarchy
Memory leak
Memory management unit
Moore’s law
N
NAND gate
NOR gate
NOT gate
O
Opcode
Operand
LOAD 10, the operand is address 10, whose contents are read into the accumulator, ACC.Operating system
Optical disc
OR gate
Output device
P
Page
Pipelining
Polling
Process
Program counter
R
RAM
Real-time operating system
Register
RISC and CISC
ROM
S
Scheduler
Secondary storage
Software
Solid-state drive
Source code
Spatial locality
SRAM
Stack
Stack overflow
Static and dynamic linking
Status flag
Stored-program concept
Swapping
System call
System on a chip
T
Temporal locality
Thermal throttling
Thrashing
Transistor
Truth table
V
Virtual machine
Virtual memory
Von Neumann architecture
W
Wear leveling
Word
Write-back
X
XOR gate
About this lesson
Make your own Study Materials
Turn your notes, slides and documents into Study Guides, Practice Questions, Flashcards and 6 more tools.