Computer Organization Semester Guide: CPU, Memory and Assembly Worked Together

Follow one set of values from memory through assembly and a five-stage pipeline, then practise cache mapping, address translation and I/O overhead.

KnowledgeGate Team

Exam prep & CS education

Updated 21 Nov 20266 min read
Computer Organization Semester Guide: CPU, Memory and Assembly Worked Together

Computer Organization Semester Guide: CPU, Memory and Assembly Worked Together

Students often memorise two's-complement rules, CPU block diagrams, assembly syntax, pipeline formulae, cache fields and DMA definitions as separate chapters, then struggle to trace one value across them. A deliberately defined 32-bit teaching machine carries 5, 7, 12 and 17 from memory through four instructions and a five-stage pipeline. It also checks -18 in 8-bit two's complement, address 0x120 in a direct-mapped cache, and CPU service overhead for a 4096-byte I/O transfer.

Use the CS Fundamentals collection when you need to place this topic beside the other core subjects.

1. Learn COA as one value-moving system, not six isolated units

The dependency chain is data representation -> ISA and assembly -> instruction cycle and datapath -> pipelining -> cache and virtual memory -> I/O organisation. The ISA says what the bits mean. The datapath moves those bits, and the pipeline overlaps those movements. Memory organisation decides where operands arrive from, while I/O extends the same movement beyond main memory.

The toy machine and selected numericals connect those ideas. Arithmetic circuits, microprogrammed control, multiprocessor coherence and complete bus protocols add separate mechanisms beyond this chain. If you also need the surrounding CS subjects, Zero to Hero provides a wider semester route. The Computer Organization and Architecture Basics survey explains definitions, overflow and one instruction-cycle example. Here, the worked path connects representation, assembly, pipeline, cache and I/O.

2. Fix the bit pattern before tracing the hardware

Start with -18 in 8-bit two's complement:

  1. 18 = 00010010

  2. Invert every bit: 11101101

  3. Add 1: 11101101 + 1 = 11101110

Check using signed weights: -128 + 64 + 32 + 8 + 4 + 2 = -18. If interpreted as unsigned, the same eight bits mean 238. A bit pattern does not determine its meaning without a representation.

Sign-extension gives 11111111 11101110, or 0xFFEE. Zero-extension gives 00000000 11101110 = 0x00EE = 238. The wrong rule changes the value before the ALU begins.

Store 0x12345678 from byte address 0x140. Little-endian memory holds 0x78, 0x56, 0x34, 0x12 at 0x140 through 0x143; big-endian holds 0x12, 0x34, 0x56, 0x78. Endianness changes placement, not the register's arithmetic value after loading the word.

3. Trace four assembly instructions through the datapath

The teaching machine has 32-bit registers, byte-addressed memory, 4-byte words and fixed 4-byte instructions. R0 stays 0. Initially, PC=0x0040, R1=0x0120, M[0x0120]=5 and M[0x0124]=7. Here, LD Rd,k(Rb) means Rd <- M[Rb + sign_extend(k)]; ADD Rd,Rs,Rt means Rd <- Rs + Rt. With these definitions, the trace is deterministic.

Code
0x0040: LD  R2,0(R1)     effective address 0x0120, R2=5
0x0044: LD  R3,4(R1)     effective address 0x0124, R3=7
0x0048: ADD R4,R2,R3     R4=5+7=12
0x004C: ADD R5,R4,R2     R5=12+5=17

The next PC is 0x0050. The first load fetches at 0x0040 and sets PC=0x0044; reads R1=0x0120; computes 0x0120+0=0x0120; reads 5; and writes R2=5. Its controls are RegWrite=1, MemRead=1, MemWrite=0, ALUSrc=immediate, MemToReg=1. ADD uses 1,0,0,register,0. Review Addressing Modes and Instruction Formats for the assembly bridge. The CPU Organization Basics post traces an accumulator machine's MAR, MDR, IR and AC state; this example traces a 32-bit load/add path.

Diagram showing R1 plus offset 0 addressing 0x0120 and loading value 5 into R2.

4. Pipeline the same program and account for the one real stall

Use five one-cycle stages, IF, ID, EX, MEM, WB, separate instruction and data access, EX forwarding, and hazard detection that freezes PC and IF/ID. There is no branch.

The schedule is:

Instruction

Pipeline timing

I1

IF1, ID2, EX3, MEM4, WB5

I2

IF2, ID3, EX4, MEM5, WB6

I3

IF3, ID4, stall/held-ID5, EX6, MEM7, WB8

I4

IF4, held-IF5, ID6, EX7, MEM8, WB9

I3 needs R3 after I2's MEM5. It forwards into I3's EX6, creating one bubble. I1's R2 is ready, and R4=12 forwards from I3 EX6 to I4 EX7, so neither adds a stall.

Without overlap, four instructions occupy 4 x 5 = 20 stage-cycles. This trace finishes in 9 cycles, giving finite-sequence speedup 20/9 = 2.22, not 5. Pipeline latency and throughput are different, and real clock overhead or unequal stage delays can reduce measured speedup.

Pipeline chart showing a load-use bubble, forwarding arrows, and completion by cycle 9.

5. Map the program's addresses through cache, TLB and main memory

Take a 64-byte direct-mapped cache, 4-byte blocks and 12-bit byte addresses. It has 64/4=16 lines, so each address splits into 6 tag bits | 4 index bits | 2 offset bits.

For 0x120 = 000100 1000 00, the block number is 0x120/4=72, the line is 72 mod 16=8, the tag is floor(72/16)=4, and the offset is 0. For 0x124 = 000100 1001 00, the block is 73, line 9, tag 4, offset 0.

With an initially empty cache, loading 0x120 misses and fills line 8 with tag 4. Loading 0x124 misses and fills line 9 with tag 4. A later access to 0x120 hits line 8. If hit time is 1 ns, miss rate is 0.05 and miss penalty is 50 ns, then AMAT = 1 + 0.05 x 50 = 3.5 ns. Under these assumptions, AMAT is 3.5 ns.

For translation, use 4 KiB pages. Virtual address 0x00004120 has VPN 0x4 and page offset 0x120. A TLB hit mapping VPN 0x4 to PFN 0x2A produces physical address 0x0002A120; the page offset survives translation. Continue with Memory Hierarchy and Virtual Memory for deeper paging and TLB treatment. For direct mapping alone, Direct Mapping in Cache Memory works through 32-bit 0x12345678 tags and conflict misses; the 12-bit split here is one step in a semester chain.

6. Compare programmed I/O, interrupts and DMA by CPU work

Assume a device transfers 4096 bytes. The CPU runs at 2 GHz, so one cycle is 0.5 ns. Programmed I/O services one 4-byte word in 25 cycles. Interrupt-driven I/O raises one interrupt per 256 bytes at 400 CPU cycles each. DMA needs 800 setup cycles and one 400-cycle completion interrupt.

Method

CPU overhead calculation

CPU service time

Programmed I/O

4096/4=1024 words; 1024 x 25=25,600 cycles

25,600 x 0.5 ns = 12.8 microseconds

Interrupt-driven I/O

4096/256=16 interrupts; 16 x 400=6,400 cycles

6,400 x 0.5 ns = 3.2 microseconds

DMA

800+400=1,200 cycles

1,200 x 0.5 ns = 0.6 microseconds

Polling repeatedly occupies the CPU. Interrupts move service to event boundaries. DMA lets a controller move the block before notifying the CPU. These figures compare CPU overhead under the stated model, not end-to-end device time. Bus arbitration, transfer rate, cache effects and overlap are outside this numerical. The Computer Interfaces in COA post works through interface registers, handshaking and occupancy windows; these 4 KiB figures isolate CPU service cycles.

7. Practise the exam-style traps that connect diagrams to numericals

  • Exam-style A: What are the signed and unsigned meanings of 11111110? In 8-bit two's complement it is -2; unsigned it is 254. Sign-extension gives 0xFFFE.

  • Exam-style B: Change I2 to LD R3,8(R1). The effective address is 0x0128, not PC+8, because this addressing mode uses R1 as the base.

  • Exam-style C: Remove forwarding from the pipeline. State whether an ID read can observe a WB write in the same cycle before counting stalls, because the answer depends on that register-file timing convention.

  • Exam-style D: Map 0x120 in the stated cache. The result is tag 4, line 8, offset 0.

  • Exam-style E: Which I/O values are CPU overhead rather than wall-clock transfer time? All three are overhead values under their stated assumptions.

Recurring traps include ignoring width and signedness, using the PC instead of the base register, quoting ideal pipeline speedup without fill and stalls, and mixing page, cache and word offsets. Use the COA question bank for optional mixed practice. University syllabi and paper instructions determine the local marks split, topic frequency and compulsory sections; the calculations above are subject examples, not a universal exam pattern.

8. Computer Organization semester short version and next step

Recall the chain: interpret bits -> compute effective address -> trace control and data -> place every pipeline stage by cycle -> split memory addresses -> count CPU work for I/O.

Now test it. Replace M[0x0124]=7 with -2: R3=-2, R4=3, R5=8. Map 0x160: block 88, line 8, tag 5, offset 0, evicting the 0x120 block from line 8. Double DMA setup to 1600 cycles: total overhead is 2000 cycles, or 1.0 microsecond. For a focused next step, use the Computer Architecture and Organisation course.