Skip to content
Tutorials Center
My learning

Topics

Lesson 66 of 67 ยท Practice and Interview

Computer Organization Interview Questions

Frequently asked computer organization and architecture interview questions on CPU, pipelining, cache, memory and number systems, with answers and runnable checks.

Interviewers ask about computer organization to find out whether you understand what happens beneath your code. They rarely want a memorized definition. They want to hear a clear explanation, a number, and ideally a consequence: "this is why the loop is slow". This lesson collects the questions that come up most often, grouped by topic, with answers short enough to say out loud. Three runnable programs let you check the claims that can be checked.

Each answer points back to the lesson that teaches the topic in depth, so you can fill any gap. If you want calculation practice rather than concepts, use Practice: Data Representation and Digital Logic and Practice: CPU, Pipeline, Cache and Virtual Memory.

The CPU and performance

What is the difference between computer architecture and computer organization? Architecture is what a programmer can see: the instruction set, the registers, the addressing modes, the data types. Organization is how that is implemented: the datapath, the control unit, the cache sizes, the pipeline depth. Two processors can share an architecture (both run x86-64 code) and have very different organizations. See What Is Computer Organization and Architecture?.

Walk me through the fetch-decode-execute cycle. The CPU sends the program counter (PC) to memory and fetches the instruction. It decodes the opcode and reads the source registers. The ALU, memory or branch logic executes it, a result is written back, and the PC is updated to the next instruction or a branch target. Then the cycle repeats. See The Von Neumann Model and the Fetch-Decode-Execute Cycle.

What is the difference between RISC and CISC? RISC machines (ARM, RISC-V) have a small set of simple, fixed-length instructions, load/store memory access and many registers, which makes pipelining easy. CISC machines (x86) have many complex, variable-length instructions that can touch memory directly. Modern x86 chips translate complex instructions into simple internal micro-operations, so the gap is mostly in the instruction encoding, not in the execution core. See Instruction Set Architecture.

Does a higher clock speed always mean a faster computer? No. Execution time = instruction count x CPI / clock rate. A processor with a faster clock but a worse CPI, or one that needs more instructions for the same work, can lose. Memory stalls, cache size and parallelism also matter, so compare programs on real benchmarks. See Measuring Performance.

State Amdahl's law and say what it implies. If a fraction p of the run time is improved by a factor s, the overall speedup is 1 / ((1 - p) + p / s). The implication is that the part you do not improve limits everything: if 10% of a program is serial, the maximum speedup on any number of cores is 10x.

Number systems and arithmetic

Why do computers use two's complement? It has one zero, and addition and subtraction use the same adder for signed and unsigned numbers, so the hardware stays simple. To negate, flip all bits and add 1. An n-bit number ranges from -2^(n-1) to 2^(n-1) - 1. See Signed Integers and Two's Complement.

What is the difference between carry and overflow? Carry says an unsigned result did not fit: a carry came out of the top bit. Overflow says a signed result did not fit: two operands with the same sign produced a result with the opposite sign. They are independent: 127 + 1 in 8 bits sets overflow without a carry, and 255 + 1 sets carry without signed overflow. See Binary Arithmetic and Overflow.

What is endianness? It is the order in which the bytes of a multi-byte value are stored in memory. Little-endian (x86, most ARM systems) stores the least significant byte at the lowest address; big-endian stores the most significant byte first (network byte order). It matters when you read binary files, send data over a network or cast pointers.

Why is 0.1 + 0.2 not 0.3? Neither 0.1 nor 0.2 has a finite binary expansion, so each is stored as the nearest representable value, and the rounding errors do not cancel. The sum is one unit in the last place away from the double nearest to 0.3. Compare with a tolerance, and never use floats for money. See Floating-Point Numbers and IEEE 754.

Python Check the number-system answers

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Pipelining and branches

What is pipelining, and does it make one instruction faster? Pipelining overlaps the stages of consecutive instructions, like an assembly line. It does not shorten the time of a single instruction (it can even lengthen it slightly because of pipeline registers). It increases throughput: ideally one instruction finishes per cycle. See Instruction Pipelining.

What are the three kinds of hazards, and how are they handled? A structural hazard is a resource conflict (two instructions want the same memory port), solved by duplicating hardware. A data hazard is a dependency on a result not yet written, solved by forwarding and, for a load followed by a use, one stall. A control hazard comes from branches whose outcome is unknown, solved by prediction and by flushing wrongly fetched instructions. See Pipeline Hazards.

How does a 2-bit branch predictor work, and why is it better than 1 bit? It keeps a saturating counter per branch with four states: strongly not taken, weakly not taken, weakly taken, strongly taken. It predicts taken in the top two states. A single surprise (a loop exit) only moves the counter one step, so the next time the loop runs the prediction is still "taken". A 1-bit predictor flips immediately and mispredicts twice per loop run. See Branch Prediction.

What is speculative execution, and why does it create security problems? The CPU runs instructions beyond an unresolved branch and discards the results if the guess was wrong. The architectural state is rolled back, but microarchitectural state such as cache contents is not, and attacks like Spectre read that leftover state through timing. See Superscalar, Out-of-Order and Speculative Execution.

Python Check the branch-predictor answer

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Cache and memory

What is locality of reference? Programs tend to reuse recently used data (temporal locality) and to use data near recently used data (spatial locality). Caches exploit both: they keep recent data, and they fetch a whole block at a time. See The Memory Hierarchy and Locality.

Explain direct-mapped, set-associative and fully associative caches. In a direct-mapped cache each block can live in exactly one line (fast, but blocks that share a line evict each other). In a fully associative cache a block can live in any line (flexible, but every tag must be compared). A set-associative cache is the compromise: the block picks a set and can live in any of its n ways. See Direct, Associative and Set-Associative Mapping.

Split a 32-bit address for a 16 KB, 4-way cache with 32-byte blocks. Offset = 5 bits (32-byte blocks). The cache has 512 blocks, so 128 sets and 7 index bits. The tag is 32 - 7 - 5 = 20 bits.

What is AMAT? Average memory access time = hit time + miss rate x miss penalty. For multiple levels, the miss penalty of one level is the AMAT of the next. See Cache Performance and the Three Cs.

What are the three Cs? Compulsory misses (first touch), capacity misses (the working set is larger than the cache) and conflict misses (too many blocks in one set). Larger blocks, larger caches and higher associativity address them in that order.

Write-through or write-back? Write-through updates memory on every store: simple and consistent, but slow without a write buffer. Write-back updates only the cache and marks the line dirty; memory is written when the line is evicted. It uses much less memory traffic and is the common choice for data caches. See Replacement and Write Policies.

Why is traversing a 2D array by columns slow in C or NumPy? Arrays are stored row by row, so walking down a column jumps a whole row between accesses. Each access touches a different cache block, and the block is evicted before its neighbours are used.

Python Check the traversal-order answer

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The second AMAT line shows a classic trap: doubling the hit time while halving the miss rate is a net win here (4.5 instead of 6.0), but only because the miss penalty is large. Always compute before deciding.

Virtual memory, I/O and parallelism

What happens when a program loads from a virtual address? The hardware looks up the virtual page number in the TLB. On a hit it gets the physical frame immediately. On a miss it walks the page table. If the page is not in memory, a page fault traps to the operating system, which loads the page from disk and restarts the instruction. The physical address then goes to the cache.

flowchart LR
  VA["Virtual address"] --> T{"TLB hit?"}
  T -- "yes" --> PA["Physical address"]
  T -- "no" --> W["Page table walk"]
  W --> P{"Page in memory?"}
  P -- "yes" --> PA
  P -- "no" --> F["Page fault: OS loads page"]
  F --> W
  PA --> C["Cache, then memory"]

The path of a load: translation first, then the cache hierarchy. See Virtual Memory and Paging for the details.

What is Belady's anomaly? With FIFO page replacement, giving a process more frames can increase its page faults. LRU and optimal replacement are stack algorithms and never behave that way.

Compare polling, interrupts and DMA. Polling makes the CPU check a device repeatedly: simple but wasteful. An interrupt lets the device signal when it is ready, so the CPU does other work meanwhile, but each interrupt has handling overhead. DMA lets a controller move a whole block between device and memory by itself and interrupt once at the end, which suits bulk transfers. See I/O Organization.

What is false sharing? Two cores write different variables that happen to sit in the same cache line. The coherence protocol bounces the line between the cores' caches on every write, even though they never touch the same data. The fix is padding or reorganizing data so that independently written variables sit in different lines. See Cache Coherence and Memory Consistency.

SRAM or DRAM for a cache? SRAM: it is faster and needs no refresh, though it uses more transistors per bit (typically six) and so costs more per bit. DRAM stores a bit as a charge in a capacitor, is denser and cheaper, and must be refreshed, so it is used for main memory. See RAM, ROM, SRAM, DRAM and Flash.

In an interview, answer in three beats: the definition, the number or example, and the consequence. "A 2-bit predictor uses a saturating counter; on a 10-iteration loop it mispredicts about once per run instead of twice; so loops stop costing a pipeline flush on every entry."

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which statement about pipelining is correct?

    Pipelining overlaps stages of different instructions, so one instruction completes per cycle in the ideal case. The latency of a single instruction does not shrink.
  2. 2. In 8-bit arithmetic, 255 + 1 gives 0. Which flag condition describes this?

    As unsigned numbers the result needed a ninth bit (a carry out). As signed numbers it is -1 + 1 = 0, which is correct, so there is no signed overflow.
  3. 3. Why does a write-back cache keep a dirty bit?

    Stores update only the cache copy. The dirty bit remembers that memory is stale, so the line is written back when it is evicted.
  4. 4. Two threads on different cores increment two different counters that share one cache line. What problem results?

    The line ping-pongs between the cores' caches even though the data is independent. Padding the counters onto separate lines removes the slowdown.
  5. 5. Which of these is part of the architecture (not just the organization)?

    The instruction set and visible registers are what software depends on. Pipeline depth, cache sizes and clock rate are implementation choices.

Summary

  • Architecture is the programmer-visible interface; organization is how it is built.
  • Know the execution-time equation, Amdahl's law and why clock rate alone misleads.
  • Two's complement, carry versus overflow, endianness and float rounding are the number-system staples.
  • Pipelining raises throughput, not latency; hazards are structural, data or control, and are handled by duplication, forwarding and prediction.
  • Cache answers need the address split, AMAT, the three Cs and the write policies; virtual memory answers need the TLB, page table and fault path.
  • Support every answer with a number and a consequence.

Finish the track with the Computer Organization Cheat Sheet.