Skip to content

Computer Organization final exam review

The topics, worked on a live board with an AI tutor.

Units

  1. Data representation

    What exams ask

    Every value a program touches, an int, a char, a memory address, a colour, is a row of bits, and debuggers, memory dumps, printf and exam questions all show those bits in hex, so you read them with these conversions or not at all.

    • Binary and hexadecimal
    • Unsigned integers and binary addition
    • Two's complement
    • Bitwise operations and shifts
    • Floating point

    Practice

    What decimal number is the byte 00101101?Answer

    45

    Hint: The 1 bits are in the places 32, 8, 4 and 1

    Add 00001111 and 00000001 as bytes. What is the sum byte, and is there a carry out?Answer

    00010000, no carry out

    Hint: The carry travels from bit 0 up to bit 4

  2. C and memory

    What exams ask

    Every array access in C, and in the assembly a compiler writes for it, is pointer arithmetic, and the array-to-pointer rule behind sizeof bugs and missing length arguments is one of the most common C errors in labs and exams.

    Structs are how C, the operating system and every file format and network packet group related data, and the field offsets with padding are what the compiler turns into the constant offsets of loads; working out sizeof a struct is a staple exam question.

    • From Python to C
    • Pointers and addresses
    • Arrays and pointer arithmetic
    • Strings in C
    • Structs
    • The heap: malloc and free
    • Memory bugs

    Practice

    What does the program print with int n = 3;?Answer

    Sum of squares to 3 is 14

    Hint: 1 + 4 + 9

    With x = 3, y = 8 and p = &y, what do *p = *p + 1; and then printf of x and y show?Answer

    x = 3 and y = 9

    Hint: p points to y

  3. RISC-V assembly

    What exams ask

    Every program, whatever its language, ends up as instructions of some instruction set, and RISC-V is the open one used in teaching and a growing share of real chips; translating C into it by hand is the first assembly skill an exam asks for.

    Compilers turn every constant, mask and shift in C into these instructions, and choosing srl or sra, or splitting a constant into lui and addi, are classic exam traps; the same skills read packed data such as colours, flags and network headers.

    • Instruction sets and registers
    • Arithmetic, logic and immediates
    • Loads and stores
    • Branches and loops
    • Machine code: instruction formats

    Practice

    Translate x = y - z + w with x, y, z, w in s4, s5, s6, s7, and give x for y = 10, z = 4, w = 1.Answer

    Sub t0, s5, s6 then add s4, t0, s7; x = 7

    Hint: C works left to right for - and +

    With r = 0xAB, g = 0x01, b = 0xFF, what does the code leave in s0?Answer

    0xAB01FF

    Hint: Each byte keeps its own two hex digits

  4. Procedures and the stack

    What exams ask

    Every function call in compiled code follows this convention, and code written by different people or compilers works together only because of it; tracing a call and spotting a broken register rule are standard exam questions.

    Any function that calls another must save its return address, and any that uses s registers must restore them; the stack frame is how compiled code does both, and drawing the stack during a call is a staple of assembly exams and of reading a debugger.

    • Calling functions
    • The stack and stack frames
    • Recursion in assembly
    • Compiling, assembling, linking and loading

    Practice

    A jal ra, f sits at 0x2A4. What is ra after it, and where does f's ret send the PC?Answer

    0x2A8, and back to 0x2A8

    Hint: PC + 4

    A function's prologue is addi sp, sp, -32 with sp = 0x8000 on entry, then sw ra, 28(sp). At what address is ra saved?Answer

    0x7FFC

    Hint: Sp becomes 0x7FE0

  5. The processor datapath

    What exams ask

    Every processor is built from these few blocks, and knowing what each one reads and writes in a cycle is what makes the single-cycle datapath, control signals and pipelining readable; exam questions ask exactly which blocks an instruction uses.

    Tracing an instruction through the datapath is how a processor's behaviour is reasoned about, and the classic exam question gives an instruction and asks which blocks it uses, what each multiplexer selects and what values appear on the wires.

    • Datapath building blocks
    • The single-cycle datapath
    • Control signals
    • Processor performance

    Practice

    A program starts at 0x2000. What address does its sixth instruction have?Answer

    0x2014

    Hint: 5 × 4 = 20 bytes later, 0x14 in hex

    Follow and x11, x6, x7 through the datapath. What does the ALU give out, and which register is written?Answer

    12 & -5 = 8, written to x11

    Hint: 12 is 01100 and -5 ends in 11011

  6. Pipelining

    What exams ask

    Every processor since the 1980s overlaps instructions in a pipeline; it is the main reason a modern core finishes about one instruction per cycle, and pipeline diagrams and speedup are standard exam questions.

    Almost every instruction uses a result computed just before it, so without forwarding a five-stage pipeline would spend most of its cycles waiting; hazard counting and code scheduling are standard exam problems and what compilers do for real.

    • Pipelining
    • Data hazards and forwarding
    • Control hazards and branch prediction

    Practice

    Six independent instructions run through this five-stage pipeline. In which cycle does the last one finish, and what is in EX in cycle 4?Answer

    Cycle 10; the second instruction is in EX in cycle 4

    Hint: k + n − 1, and instruction i is in EX in cycle i + 2

    Without forwarding, how many stall cycles does add x1, x2, x3; or x9, x2, x2; sub x4, x1, x5 need, and how many cycles in all?Answer

    1 stall, 8 cycles

    Hint: Sub is at distance 2 from add

  7. Caches and the memory hierarchy

    What exams ask

    Every load and store your program runs goes through a cache first; how addresses map to cache lines decides whether an access costs about one cycle or a hundred, and exams ask for exactly this split and this trace.

    A miss can cost a hundred times a hit, so a few percent of misses decide how fast a program runs; average memory access time is how architects and exams compare cache designs.

    • The memory hierarchy and locality
    • Direct-mapped caches
    • Cache performance
    • Set-associative caches
    • Writing cache-friendly code
    • Virtual memory

    Practice

    About how many 3 GHz cycles does an L3 read of 15 ns cost?Answer

    About 45 cycles

    Hint: One cycle is a third of a nanosecond

    Split 0x1E for this cache.Answer

    0001 11 10: tag 1, index 3, offset 2

    Hint: 0x1E is 0001 1110

Questions

What does the Computer Organization review cover?

Every unit of the course, 7 in all. Pick one and Helio teaches it on the board, then asks you questions. Data representation; C and memory; RISC-V assembly; Procedures and the stack; The processor datapath; Pipelining; Caches and the memory hierarchy.

Can it help the week before my final?

Yes. Pick a topic, and Helio explains it, checks you and goes over what you miss.

Is it the same as my class?

It follows the usual topics of Computer Organization. For anything else on your syllabus, type the topic and Helio teaches that too.

How much is free?

30 minutes a month for one learner, with no card. Starter is free for 7 days with a card: cancel in time and pay nothing.

A tutor you can talk to

30 minutes every month. No card.