Computer Organization
College7 units and 34 lessons. Helio talks each one through and draws each step on a board.
Units
Data representation
5 lessons- Binary and hexadecimalConvert a whole number between decimal, binary and hexadecimal by place value and by grouping four bits to a hex digit, and read what a C uint8_t holds.
- Unsigned integers and binary additionAdd two n-bit unsigned numbers column by column with carries, and tell from the carry out of the top bit whether the sum overflowed and what the wrapped result is.
- Two's complementRead and write signed 8-bit integers in two's complement, negate one by inverting the bits and adding 1, and tell when a signed sum overflows.
- Bitwise operations and shiftsUse the C operators &, |, ^, ~, << and >> to test, set, clear and toggle single bits with masks, and to multiply and divide by powers of two.
- Floating pointEncode a number as an IEEE 754 single precision float (sign, biased exponent, fraction), decode a float from its hex pattern, and explain from the format why 0.1 + 0.2 is not exactly 0.3.
C and memory
7 lessons- From Python to CCompile and run a typed C program with printf and a for loop, fix what gcc reports, and give the sizes of C's basic types.
- Pointers and addressesTake addresses with &, follow them with *, draw memory as named boxes with addresses, and swap two ints through pointers.
- Arrays and pointer arithmeticShow that a[i] is *(a + i), that p + 1 moves by the size of the pointed-to type, and that an array passed to a function arrives as a pointer.
- Strings in CStore strings as char arrays ending in '\0', write strlen and a copy loop, and predict what a missing terminator, a too-small buffer and a write to a string literal do.
- StructsDefine structs, access fields with . and ->, pass them by value or by pointer, and lay a struct out in memory with its padding and alignment.
- The heap: malloc and freePlace code, globals, the heap and the stack in a process's memory, allocate with malloc and release with free, and build an array that grows with realloc.
- Memory bugsFind dangling pointers, double frees, memory leaks and buffer overflows in short C programs, say what each corrupts, and catch them with gcc's AddressSanitizer.
RISC-V assembly
5 lessons- Instruction sets and registersSay what an instruction set architecture defines, name RISC-V's 32 registers and their roles, and translate C statements like a = b + c - d into add and sub.
- Arithmetic, logic and immediatesTranslate C expressions with constants, shifts and bitwise operators into addi, and, or, xor, sll, srl and sra and their immediate forms, and load any 32-bit constant with li or lui and addi.
- Loads and storesTranslate A[i] = A[i - 1] + 5 and string byte accesses into lw, sw, lb, lbu and sb, computing each element's byte address.
- Branches and loopsTranslate if, if-else and while loops into RISC-V with beq, bne, blt, bge and labels, and trace a loop that sums an array, counting the instructions it runs.
- Machine code: instruction formatsEncode and decode R, I, S and B type RISC-V instructions field by field, in binary and in hex.
Procedures and the stack
4 lessons- Calling functionsCall and return with jal and jalr, pass arguments in a0 to a7 and the result in a0, and decide which registers a caller and a callee must preserve.
- The stack and stack framesWrite a function's prologue and epilogue that move sp and save ra and s registers in a stack frame, and draw the stack and registers as nested calls run.
- Recursion in assemblyWrite recursive factorial in RISC-V and hand-trace fact(3) frame by frame, with sp, the saved ra and n, and a0 at every call and return.
- Compiling, assembling, linking and loadingFollow a two-file C program through the compiler, assembler, linker and loader, read each object file's symbol table, and say which addresses relocation fills in and when.
The processor datapath
4 lessons- Datapath building blocksName the program counter, instruction memory, register file, ALU, immediate generator, data memory and multiplexers, and say what each reads and writes in one clock cycle while add, lw and sw run.
- The single-cycle datapathFollow add, lw, sw and beq through the single-cycle datapath, naming the path each takes, the choice each multiplexer makes and the next PC.
- Control signalsSet RegWrite, ALUSrc, MemRead, MemWrite, MemtoReg and Branch for R-type, lw, sw and beq, explain each don't-care, and find the critical path that sets the single-cycle clock.
- Processor performanceCompare two machines, two compilers and an improvement by CPU time = instruction count × CPI ÷ clock rate, with the CPI found from the instruction mix and the limit from Amdahl's law.
Pipelining
3 lessons- PipeliningDraw the pipeline diagram of a short RISC-V sequence through the five stages, and compute the clock period, the total time and the speedup of a pipelined design over a single-cycle one.
- Data hazards and forwardingFind the read-after-write hazards in a RISC-V sequence, count the cycles it takes with stalls alone and with forwarding, and reorder code to remove a load-use stall.
- Control hazards and branch predictionCount the cycles a taken branch costs in the five-stage pipeline, and compare stalling, predicting not taken and 1-bit and 2-bit dynamic prediction on a loop, as extra cycles and as CPI.
Caches and the memory hierarchy
6 lessons- The memory hierarchy and localityPlace registers, caches, DRAM and SSD in the memory hierarchy by size and speed, and find temporal and spatial locality in a loop.
- Direct-mapped cachesSplit an address into tag, index and offset for a direct-mapped cache, and trace the hits and misses of an address sequence through it.
- Cache performanceCompute hit rate and average memory access time for one and two cache levels, and classify misses as compulsory, capacity or conflict.
- Set-associative cachesSplit an address for an n-way set-associative cache and trace accesses through it with LRU replacement, comparing its misses with a direct-mapped cache of the same size.
- Writing cache-friendly codeCount the cache misses of a row-by-row and a column-by-column loop over a C array, and choose the loop order and write policy that keep misses low.
- Virtual memoryTranslate a virtual address to a physical address through a page table, recognise a page fault, and count the TLB hits of an access sequence.



