C8 Computer organization · Practice
Every topic, mixed
Problems dealt one at a time, with new numbers every time. The kinds you miss come back more often, and you can keep going as long as you like.
Topics: all 55
Check
The PC holds 0x0120. With no branches taken, what does it hold after 2 more instructions?
Check
A processor has 16 registers. How many bits does an instruction need to name one of them?
Check
A single-cycle processor's slowest instruction takes 2.5 ns to settle from one clock edge to the next. What's the fastest clock it can use?
Write units the way you normally would: 1.5 MHz, 1500 kHz and 0.0015 GHz are the same answer.
Check
A single-cycle processor (CPI = 1) at 50 MHz runs a program of 500 thousand instructions. How long does it take?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
A multi-cycle processor at 50 MHz takes 6 cycles for loads (30% of instructions) and 3 for the rest, running 5 million instructions.
(a)
What's its average CPI?
(b)
How long does the program take?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
The PC is 0x00AC. After 4 instructions with no branch, the PC?
Check
How many address bits does a memory of 4 KiB (1 KiB = 1024 bytes) need?
Check
A single-cycle CPU's longest path is 2 ns. Fastest clock?
Write units the way you normally would: 1.5 MHz, 1500 kHz and 0.0015 GHz are the same answer.
Check
40 thousand instructions at a CPI of 1.5 on a 50 MHz clock. Run time?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
RV32I has no multiply instruction. With n in a0, put 5 × n in a1 using shifts and adds.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
With n in a0, put n with its lowest 4 bits cleared into a1. Use one instruction before the ebreak.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
Encode addi x12, x0, 217 as a 32-bit word in hex.
Check
The assembler splits li a0, 0x066228D8 into lui and addi. What 20-bit value does lui load?
Check
What's the largest value a signed 8-bit immediate can hold?
Check
a0 holds a negative number and a1 a shift amount. Put a0 shifted right arithmetically by a1 into a2.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
t0 holds −99 and is shifted right by 1.
(a)
What does srai give?
(b)
What does srli give, as an unsigned number?
Check
With n in a0, put 9 × n in a1 using shifts and adds.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
Smallest value of a signed 10-bit field?
Check
addi x12, x0, 217 in hex?
Check
t0 holds 36. What does slli t1, t0, 1 put in t1?
Check
a1:a0 and a3:a2 hold two 64-bit numbers (high word first). Put their sum in a5:a4.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
Two unsigned 32-bit numbers, 3 × 10⁹ and 1.5 × 10⁹, are added.
(a)
What does add leave, as an unsigned number?
(b)
What carry does sltu find (1 or 0)?
Check
An n-bit register, n = 12.
(a)
What's the most negative two's-complement value?
(b)
What's the largest unsigned value?
Check
a0 holds a signed number and a1 a positive one. Put their sum in a2, saturated: if the addition overflows, a2 gets the largest signed value, 0x7FFFFFFF, instead.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
a0 holds −100 and t0 holds 10.
(a)
What unsigned value does bgeu see in a0?
(b)
Does bgeu a0, t0, out branch (1 for yes)?
Check
What does mulhu give for 2596069104 × 3?
Check
What does add leave for 4294967295 + 1 (unsigned)?
Check
What unsigned number has the same bits as −16?
Check
Does 9 − 9 borrow in unsigned arithmetic (1 for yes)?
Check
Encode addi x10, x0, 7 as eight hex digits.
Check
Encode add x10, x2, x12 (R-type, opcode 0x33, funct3 and funct7 zero).
Check
What destination register number (rd) does the instruction 00812503 write?
Check
What is the opcode of 00812503, in hex?
Check
A field holds a 20-bit two's-complement immediate. What is the largest value it can hold?
Check
lui a0, 4096 is followed by addi a0, a0, 100. What value does a0 hold?
Check
Encode addi x10, x2, 2000 (I-type: imm in bits 31:20, rs1 in 19:15, funct3 000, rd in 11:7, opcode 0x13).
(a)
What's the 32-bit encoding?
(b)
What does bits 31:24 of that word hold, as a number? (They're the top 8 bits of the 12-bit immediate.)
Check
What is rd = x5 shifted into its field (bits 11:7), as a 32-bit word?
Check
How many different values does a 7-bit field hold?
Check
Write the 12-bit immediate field for −16 in hex.
Check
A program executes 1 billion instructions at an average CPI of 1.2 on a 4 GHz processor. How long does it take?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
Check
Design A runs 1 billion instructions at CPI 1.4. Design B needs 1.4 times as many instructions at CPI 1.2. Both run at the same clock.
(a)
What is B's run time as a fraction of A's?
(b)
What CPI would B need to tie A?
Check
In a RISC-V program, a fraction 0.6 of instructions compress to 2 bytes and the rest stay 4 bytes. What's the average instruction size?
Check
A loop of 600 x86 instructions, 1.1 micro-operations each, is limited by decoding at 5 instructions per cycle. A micro-operation cache delivers 8 per cycle. How many cycles per iteration does the cache save?
Check
Memory holds a at 0x1000, b at 0x1004 and c at 0x1008 (the starter stores them). Compute a = b + c with loads and a store, as a RISC machine must.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
Model code size. A program has n = 2500 instructions; their kinds and proportions are: arithmetic 45% (compressible 70% of the time), loads and stores 30% (compressible 60%), branches and jumps 15% (compressible 50%), other 10% (never). Compute size_rv32 (bytes, all 4-byte), size_rvc (bytes, compressed where possible, using the expected counts) and saving (the fractional reduction).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
How long do 2 billion instructions at CPI 1.2 take at 2.5 GHz?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
Check
If a fraction 0.55 of 4-byte instructions compress to 2 bytes, by what fraction does the program shrink?
Check
An array of 32-bit words starts at 0x1578. At what address does element 5 start (counting from 0)?
Check
The word 0xFAAB4621 is stored at address 0x1000. Which byte is at address 0x1000?
Check
The byte at an address is 0xAD. What value does lb (load byte, signed) put in a register?
Check
Swap the two words in data memory, so that a holds what b held and b holds what a held.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
A processor has 20-bit addresses. How much memory can it address, in KiB (1 KiB = 1024 bytes)?
Check
An array of 8-byte elements starts at address 4096.
(a)
Where is element 3?
(b)
What offset does a load from the base register use?
Check
sh stores the halfword BEEF at address 0x1002.
(a)
Which byte is at 0x1002?
(b)
And at 0x1003?
Check
Word array at 0x20B0. Address of element 7?
Check
0xFAAB4621 at 0x2000, little-endian. Byte at 0x2000?
Check
lb reads the byte 0xAD. Result?
Check
Store 718 into word 2 (counting from 0) of the array that starts at 0x1000.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
What's 2783 (a 12-bit field) sign-extended?
Check
A program runs 5 million instructions at an average of 1.4 cycles each on a 400 MHz clock.
(a)
How long does it take?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
How many million instructions does it run per second?
Check
A program's first instruction is at 2000, and it runs straight through with no branches.
(a)
At what address is instruction number 3 (counting the first as 0)?
(b)
How many bytes do instructions 0 to 3 take?
Check
Consider addi x6, x0, 1.
(a)
What is its 32-bit encoding?
(b)
What does x6 hold after it runs?
Check
Encode the R-type instructions below (opcode 0x33, funct3 = 0).
(a)
add x7, x1, x30
(b)
sub x7, x1, x30
Check
An instruction word reads 00203693.
(a)
What register number is in its rs1 field (bits 19:15)?
(b)
What is its funct3 (bits 14:12)?
Check
A program builds a constant with lui t0, 74565 then addi t0, t0, 291.
(a)
What value does t0 hold?
(b)
What did t0 hold after the lui alone?
Check
An array of 4-byte elements starts at 1000.
(a)
What is the address of element 2?
(b)
How far apart are neighboring elements?
Check
The word AABBCCDD is stored at 0x1000 on this little-endian machine.
(a)
What byte is at 0x1000?
(b)
What does lbu from 0x1001 give?
Check
The byte AD is in memory.
(a)
What does lb load?
(b)
What does lbu load?
Check
A region of memory is addressed by the low 16 bits of the address.
(a)
How many bytes does it cover?
(b)
How many 32-bit words is that?
Check
A load uses the address 1004.
(a)
How many bytes past the start of its word is it? (0 means it's aligned for lw.)
(b)
At what address does the word containing it start?
Check
The stack pointer starts at 10000 and a function makes a frame of 4 words.
(a)
What does sp hold inside the function?
(b)
How many bytes is the frame?
Check
t0 = 25 and t1 = 3 when the instructions below run, in order.
(a)
sub t2, t0, t1 puts what in t2?
(b)
slli t3, t2, 2 then puts what in t3?
Check
Two 64-bit numbers are held as high and low words: (17, 4 × 10⁹) and (9, 8 × 10⁸).
(a)
What does add leave in the low word of the sum?
(b)
What is the high word of the sum?
Check
A branch instruction is 00628863. (B-type: bit 31 is imm[12], bits 30:25 imm[10:5], bits 11:8 imm[4:1], bit 7 imm[11].)
(a)
What byte offset does it encode?
(b)
What is its funct3?
Check
A CISC design runs 1 billion instructions at CPI 1.6; a RISC design needs 1.4 times as many at CPI 1.2. Both run at 2 GHz.
(a)
How long does the CISC design take?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
(b)
And the RISC design?
Check
With n in a0, put 1 + 2 + … + n into a1.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
a0 and a1 hold two signed numbers. Put the larger of them in a2.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
A branch at address 0x080C jumps back to a label at 0x07F4. What offset, in bytes, is stored in the instruction?
Check
How many times does the body of this loop run?
li t0, 18
loop:
... # the body
addi t0, t0, -4
bgtz t0, loopCheck
With n in a0, put n × (n − 1) into a1 using only additions in a loop (no mul).
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
A bottom-tested loop runs a 2-instruction body 100 times with 2 instructions of overhead per pass and 2 to set it up.
(a)
How many instructions does it execute?
(b)
And unrolled by 4?
Check
With n in a0, put 2 + 4 + … + 2n into a1.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
A branch at 0x060C jumps forward to 0x062C. Offset in bytes?
Check
li t0, 17, then a body ending addi t0, t0, -5 and bgtz t0, loop. Passes?
Check
An array of 8-byte elements starts at 1000. What is the address of element 3?
Check
The byte AD is loaded with lb. What signed value does the register hold?
Check
Add the five words of the array vals and leave the sum in a0.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
With n in a0, put 10 × n in a1 using shifts and adds (no multiply).
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
The array vals holds the words 1, 2, 3, and so on. With its address in a0 and a count n in a1, put the sum of the first n words into a2.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
A string of 12 characters is measured by a loop of four instructions per character, plus two for the terminating zero.
(a)
How many instructions run?
(b)
And with the test moved to the bottom (load, increment, branch back), plus 3 instructions around it?
Check
How many bytes does a 12-character C string occupy?
Check
The byte 2E is loaded with lb. What value results?
Check
How many bytes past the start does the end pointer of a 50-word array sit?
Check
A struct starts with 3 chars, then a short, then an int.
(a)
At what offset does the short start?
(b)
What's its size?
Check
An array of 12-byte structs starts at 0x2000 (8192). A field sits at offset 6.
(a)
At what address is element 3's field?
(b)
How far does p++ move a pointer to these structs?
Check
recs holds four struct { int id; int value; }. Put the sum of the value fields in a0.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
A union holds char c[5], an int i and a short s.
(a)
What's its size?
(b)
i is set to 11223344. What does c[0] read on a little-endian machine?
Check
A big-endian 16-bit field arrives as the bytes 5 then 44.
(a)
What value did the sender mean?
(b)
What does lhu read from it on RV32?
Check
A loop reads one 4-byte field from each of 1000 records of 16 bytes, with 64-byte cache lines.
(a)
How many lines does it touch as an array of structs?
(b)
And with the field in its own array?
Check
A status word in a0 holds a 6-bit field in bits 11:6. Put the field's value in a1.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
The next free offset is 5. Where does a field with alignment 2 go?
Check
20-byte structs start at 4096. Where does element 2 start?
Check
A big-endian halfword arrives as bytes 10, 3. What does a little-endian lhu read?
Check
A bump allocator aligns to 8 bytes. How much space does a request for 9 bytes take?
Check
A node holds 8 bytes of data and a 4-byte pointer. The allocator adds an 8-byte header and rounds the total to a multiple of 16.
(a)
How many bytes does each node use?
(b)
What percentage of that is the data itself?
Check
Summing a 1000-node linked list costs a 50-cycle cache miss per node; summing an array of the same 1000 values costs one cycle per value. How many times longer does the list take?
Check
A heap is filled with 16 blocks of 64 bytes, and every second block is freed. How much memory is free in total?
Check
Three nodes are built at 0x1000, 0x1010 and 0x1008 (value, then link), linked in that order and ending with a 0 link. Starting from the head at 0x1000, count the nodes into a0 by following the links.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
Write a first-fit allocator over a heap of H = 1024 bytes. alloc(n) rounds n up to 8, finds the lowest-addressed free block big enough, splits it, and returns the address (or None); release(addr) frees the block and merges it with free neighbors. Keep blocks as a sorted list of [addr, size, free]. Then run the workload: with rng = random.Random(seed), repeat 500 times: if rng.random() < 0.6, allocate rng.randrange(8, 129) bytes (record successes), else free a random live block (rng.randrange(len(live)), removing it from the list) if any. Set failures (failed allocations) and largest (the largest free block at the end).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
With 4-byte alignment, how many bytes does a 17-byte request occupy?
Check
Nodes hold 4 bytes of data, a 4-byte link and an 8-byte header (sizes already aligned). What percentage is data?
Check
A loop runs 50 times with a 3-instruction body.
(a)
With the test at the top (a branch out, the body, a jump back), how many instructions run, counting the final failed test?
(b)
With the test at the bottom (the body, then a branch back while not done)?
Check
A branch at address 1024 goes back 3 instructions to the top of a loop.
(a)
What byte offset does it encode?
(b)
What is the target address?
Check
short m[5][25] starts at 8192, stored row by row.
(a)
Where is m[3][1]?
(b)
How many bytes apart are m[i][j] and m[i + 1][j]?
Check
strcmp compares two strings byte by byte. They first differ at position 8 (counting from 0).
(a)
How many passes does its loop make?
(b)
How many byte loads does it make?
Check
On RV32, struct { char a; T b; char c; } where T is a 4-byte type aligned to 4.
(a)
How big is the struct?
(b)
And with b first?
Check
struct rec { int id; short x; short y; char tag[8]; } (20 bytes) is stored in an array from 4096.
(a)
What address does recs[2].y read?
(b)
And recs[2].tag[3]?
Check
The word DEADBEEF is stored at 0x1000.
(a)
What does lbu read from 0x1001?
(b)
What does lhu read from 0x1000?
Check
A big-endian 32-bit field arrives as the bytes 18, 2, 86, 120.
(a)
What value does it hold?
(b)
What does lw read on RV32?
Check
A linear search through 50 words runs 5 instructions a pass, plus 2 to set up. The value sits at index 9.
(a)
How many instructions does it run to find it?
(b)
And for a value that isn't there?
Check
int *p and short *q both hold 4096.
(a)
What does p + 3 hold?
(b)
And q + 3?
Check
A status word 12345678 holds a 5-bit field starting at bit 4.
(a)
What is the field's value?
(b)
What mask selects it in place?
Check
A switch on x with cases 0 to 10 − 1 compiles to a jump table of word addresses at 8192.
(a)
Which address holds the target for x = 2?
(b)
How many bytes is the table?
Check
A nested loop: the outer runs 10 times with 3 instructions of its own; the inner runs 8 times per outer pass, each pass 4 instructions plus 2 of loop overhead.
(a)
How many instructions in all?
(b)
What share of them is the inner loop's overhead?
Check
A loop adds 3 copies of 9 × 10⁸ into a 32-bit signed register.
(a)
What does the register hold?
(b)
What true sum should it have held?
Check
A word copy loop runs lw, sw, two pointer addis, a count addi and a bnez, 6 instructions per word, after 3 to set up. It copies 100 words.
(a)
How many instructions does it run?
(b)
How many would a byte-by-byte copy of the same data take, with the same loop shape?
Check
A list of 1000 nodes holds 8 bytes of data and a 4-byte link per node, from an allocator with an 8-byte header that rounds blocks to multiples of 8.
(a)
How many bytes of heap does the list use?
(b)
How many times the size of a plain array of the same data is that?
Check
sp holds 0xADF0. A chain of 1 nested calls each makes a 16-byte frame. What does sp hold at the deepest point?
Check
Finish triple, a function that returns 3 × its argument. The main program passes n in a0 and calls it.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
Finish nine, which returns 9 × its argument by calling triple twice. The stack must be back where it started when the program stops.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
A recursive function makes a 32-byte frame on each call, and the stack has 1 KiB (1 KiB = 1024 bytes). How many calls deep can it go before the stack runs out?
Check
A function uses 2 saved registers and makes calls if c = 1 (here c = 0).
(a)
How many registers must it save on the stack?
(b)
How big is its frame, keeping sp a multiple of 16?
Check
sp = 0xADF0. After 1 16-byte frames, sp?
Check
512 bytes of stack, 32-byte frames. Maximum depth?
Check
Finish add3, which returns the sum of its three arguments.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
A recursive function with a 16-byte frame is called with n = 100; levels n down to 2 each make a frame before recursing, and level 1 returns at once. How much stack is in use at the deepest point?
Check
How many calls does the naive recursive Fibonacci make to compute F(8)?
Check
With n in a0, leave the Fibonacci number F(n) in a0, where F(0) = 0, F(1) = 1 and each later one is the sum of the two before. (A recursive version or a loop: either is fine.)
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
A naive recursive Fibonacci computes F(10) with 16-byte frames.
(a)
How much stack does it use at the deepest point?
(b)
How many additions does a loop need instead?
Check
With n in a0 (at most 12), put n! into a1.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
How much stack do 20 live frames of 16 bytes take?
Check
A function needs 40 bytes of locals and saved registers. How large is its frame, keeping sp a multiple of 16?
Check
A function recursing 6 levels deep with 16-byte frames is rewritten as a loop that uses a single frame. How many bytes of stack does that save at the deepest point?
Check
A loop has 3 setup instructions, then a body of 4 instructions (its test included) that runs 1000 times, and one final test that leaves the loop. Each instruction takes one cycle at 50 MHz.
(a)
How many instructions run in all?
(b)
How long does it take?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
A branch at 1130 jumps back 3 instructions, to the top of its loop.
(a)
What offset is stored in the branch?
(b)
What is the target address?
Check
jal ra, f sits at 1100, and the function f starts at 1400.
(a)
What does ra hold after the jump?
(b)
What offset does the jal hold?
Check
a0 = −5 and a1 = 1.
(a)
What is a0 read as an unsigned number?
(b)
What does slt a2, a0, a1 put in a2?
(c)
What does sltu a2, a0, a1 put in a2?
Check
An array of 5 words starts at 2000, and a loop walks a pointer through it.
(a)
Where does the end pointer, just past the last element, point?
(b)
Where is the last element?
Check
A C string of 5 characters starts at 1000.
(a)
At what address is its terminating zero?
(b)
How many bytes does it occupy?
Check
The halfword 9C40 is in memory.
(a)
What does lh load?
(b)
What does lhu load?
Check
A function calls other functions and uses 2 saved registers (s0 upward) for values that must survive those calls.
(a)
How many registers must it save on the stack?
(b)
How large is its frame, rounded up to a multiple of 16 bytes?
Check
A recursive function makes one 16-byte frame per level and goes 20 levels deep before the base case, which makes no frame. sp starts at 0x10000.
(a)
How much stack is in use at the deepest point?
(b)
What is sp at the deepest point?
Check
The naive recursive Fibonacci computes F(8).
(a)
How many calls does it make?
(b)
How many additions does a loop starting from F(0) and F(1) need instead?
Check
A count-down loop runs addi t1, t1, -1 then bnez t1, loop each pass.
(a)
If t1 starts at 10, how many passes does it make?
(b)
If t1 starts at 0 by mistake, how many passes does it make?
Check
A function takes 10 word-sized arguments. The calling convention passes the first eight in a0 to a7 and the rest on the stack.
(a)
How many arguments go on the stack?
(b)
How many bytes of stack do they take?
Check
A recursive fact(n) uses 16-byte frames, and fact(1) returns without making one. The stack holds 4096 bytes.
(a)
How much stack does fact(12) use at its deepest?
(b)
What is the largest n whose recursion fits?
Check
A function uses 3 saved registers and 6 bytes of locals; it calls other functions if c = 1 (here c = 0).
(a)
How many registers does it save in its frame?
(b)
How big is its frame?
Check
A loop reverses a string of 25 bytes in place by swapping from both ends; each swap pass runs 8 instructions, after 4 to set up.
(a)
How many swaps does it make?
(b)
How many instructions does it run?
Check
How many instructions does sum run for an array of 75 elements, from its first instruction to its ret?
Check
An array whose elements are 8 bytes each starts at 0x1578. What's the address of element 6?
Check
Translate this C, with x in a0 and y in a1:
y = x;
if (y < 0) {
y = -y;
}RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
Translate this C, with n in a0 and f in a1:
int f = 1;
for (int i = 0; i < n; i++) {
f = f * 2;
}RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
a0 points to struct { int id; int count; }. Add a1 to s->count, store it back, and leave the new count in a2.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
int m[10][8] is stored row by row from address 0.
(a)
At what address is m[3][7]?
(b)
How many bytes apart are m[i][j] and m[i + 1][j]?
Check
Element 9 of an array of 8-byte items at 0x1B14?
Check
A loop's body is 5 instructions; each pass adds a test and a jump back. It runs 8 passes and leaves on one last test. Instructions?
Check
Translate if (a > b) m = a - b; else m = b - a; with a in a0, b in a1, m in a2.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
An 8-bit LED register holds 0x29, with LED 1 off. What value turns LED 1 on and leaves the others as they are?
Check
What 8-bit mask do you AND a register with to clear bit 2 and keep the others?
Check
The LEDs already show a pattern. Turn on LED 2 (bit 2) without changing any of the others. Read the pattern from the LED register; don't write it in.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
Light each LED whose switch is off, and turn off each LED whose switch is on. (Read the switches once, then stop.)
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
The switch register reads 0x5B. What is (*switches >> 0) & 1?
Check
A register holds 3C. Set its bits 7:4 to 2 and leave the others alone.
(a)
What does it hold afterward?
(b)
What's left after the AND with ~0xF0, before the OR?
Check
Toggle bit a1 of a0 and put the result in a2.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
Register 0x29; set bit 1. New value?
Check
8-bit mask to clear bit 2?
Check
The LEDs show a pattern. Flip LED 2 (on to off, or off to on), leaving the rest.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
Leave the largest of the five signed words in vals in a0.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
Copy the three words at src to dst (src is at 0x1000, dst at 0x100C).
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
Count the 1 bits in a0 (an 8-bit value) and leave the count in a1.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
a0 and a1 hold two positive numbers. Leave their greatest common divisor in a0.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
What does andi t0, a0, 1 leave in t0 when a0 = 92?
Check
A .data section starts at 0x1000 with a list of words. Where is word 4 (counting from 0)?
Check
For two positive numbers 30 and 18, what is the most subtraction steps Euclid's algorithm by subtraction could possibly need (a loose bound: a + b − 1)?
Check
What integer represents 0.25 in Q15?
Check
Two Q15 numbers, 16384 and 6554, are multiplied with mul and the product shifted right by 15 (rounding down). What integer results?
Check
A 12-bit ADC with a 2500 mV reference reads 1534. What does mul by 2500 followed by srli by 12 give, in millivolts?
Write units the way you normally would: 1.5 mV, 1500 µV and 0.0015 V are the same answer.
Check
What does div give for −23 ÷ 2?
Check
What does rem give for −23 and 2?
Check
Compute the dot product of the three-word vectors p and q (the sum of p[i] × q[i]) and leave it in a0.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
a0 holds a 12-bit ADC code; the reference is 3300 mV. Put the reading in millivolts in a1, rounded down.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
Multiply 0.45 by 0.25 in Q15.
(a)
What integer stores 0.45?
(b)
What Q15 integer does the product, shifted right 15, give?
Check
What is the step between adjacent values of a Q-format number with 15 fraction bits?
Check
What value does the Q15 integer 8192 represent?
Check
How many bits can the product of an unsigned 12-bit number and an unsigned 10-bit number need?
Check
What is the spacing between adjacent single-precision floats near 100?
Check
A float has sign 0, stored exponent 3 + 127 and significand bits equal to 1048576. What value does it hold?
Check
A filter needs 1000 multiply-adds per output sample. Without an FPU each costs 80 cycles. At 200 MHz, how many samples per second can it produce?
Check
A float format has a 24-bit significand (counting the hidden 1). What's the largest integer below which every integer is exactly representable?
Check
In float, a program computes with = 3000000 and = 0.01.
(a)
What is the spacing of floats near 3000000?
(b)
What does the expression return? (Round to the nearest multiple of that spacing.)
Check
Compare summation orders in single precision. Write to_f32(x) that rounds a Python float to the nearest float32 (use struct), and fsum32(values) that adds them one by one with a float32 accumulator. Also write kahan32(values), Kahan's compensated sum with every operation rounded to float32. For the harmonic series , = 1 to n (20000), set fwd, bwd and kahan (forward order, backward order, Kahan forward), and exact from math.fsum in double.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
What is one ULP of a float near 900?
Check
How long do 64 software float operations of 60 cycles take at 72 MHz, in µs?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
An array starts at 2000, and the code reads element 3.
(a)
Where is a[3] if a is an int array?
(b)
Where is it if a is a short array?
Check
struct point { int id; int x; int y; } takes 12 bytes, with id at offset 0, x at 4 and y at 8. An array pts of these starts at 1000.
(a)
What address does pts[2].y read?
(b)
What offset does the lw use if a register already points at pts[2]?
Check
A device register holds 5B.
(a)
What does it hold after r |= (1 << 0)?
(b)
What does (r >> 0) & 1 give for the original value?
Check
A device register holds 5B.
(a)
What does it hold after r &= ~(1 << 1)?
(b)
What would it hold after r ^= (1 << 1) instead?
Check
A control register keeps a 3-bit field in bits 4 upward.
(a)
What mask selects the field?
(b)
What is the largest value the field can hold?
Check
Two numbers, 0.35 and 0.3, are stored in Q15.
(a)
What integer holds 0.35?
(b)
Their integers are multiplied, is added and the sum is shifted right by 15. What integer results?
Check
A 12-bit ADC with a 2500 mV reference reads 3358.
(a)
What does multiplying by 2500 and shifting right by 12 give?
Write units the way you normally would: 1.5 mV, 1500 µV and 0.0015 V are the same answer.
(b)
What is the largest product the multiply can produce?
Check
Signed division with div and rem, which round toward zero.
(a)
What does div give for 23 ÷ −2?
(b)
What does rem give for 23 and −2?
Check
The assembly lab's bit counters are run on 100.
(a)
How many passes does the x & (x - 1) loop make?
(b)
How many passes does a loop make that tests the low bit and shifts right until x is 0?
Check
A compiler computes x × 20 as (x << p) + (x << q) with p > q.
(a)
What is p?
(b)
What is q?
Check
int *p and char *q both hold 1000.
(a)
What address does p + 3 hold?
(b)
What address does q + 3 hold?
Check
A 16-bit Q8.8 number has 8 integer bits (sign included) and 8 fraction bits.
(a)
What integer stores 3.25?
(b)
What is the largest value Q8.8 can hold?
Check
A compiler multiplies x = 777 by 3 with a shift and an add: (x << p) + x.
(a)
What is p?
(b)
What does it compute?
Check
−2.25 and 0.5 are stored in Q8.8 and multiplied as integers.
(a)
What is the integer product?
(b)
What Q8.8 integer does shifting right by 8 give?
Check
for (i = 0; i < n; i++) a[i] = b[i] + c; runs with n = 200.
(a)
Indexed, each pass computes two addresses (slli, add, add), loads, adds, stores, increments i and branches: 8 instructions. How many in all?
(b)
With two pointers walking (load, add, store, two pointer addis, branch on an end pointer), how many?
Check
A filter on a microcontroller without an FPU works on floats near 300, doing 200 software multiply-adds per sample at 150 cycles each, at 200 MHz.
(a)
What's the spacing between floats near 300?
(b)
How many samples per second can it filter?
Check
a0 points to an array of a1 signed words (here 5). Return the largest in a0.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
a0 points to the string "hello, world" (ending in a zero byte), and a1 holds a character code. Return in a0 how many times that character appears.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
Count the 1 bits in a0 and return the count in a1.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
Copy a2 words from the address in a0 to the address in a1 (here 4 words, from src to dst).
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
Return in a0 the greatest common divisor of a0 and a1, using Euclid's algorithm with remu.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
square (provided) returns a0² and clobbers t0 and t1. With n in a0, call it for each i from 1 to n and return the sum of the squares in a0.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
Write sum recursively: sum(0) = 0 and sum(n) = n + sum(n − 1). Main calls it with n in a0. Each level must save what it needs on the stack, and sp must end where it started.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
A function that calls other functions uses 2 saved registers and 8 bytes of local variables.
(a)
How many bytes does it need to store?
(b)
How big is its frame?
Check
A recursive function uses 16-byte frames on an 8192-byte stack.
(a)
How much stack does recursion 50 levels deep use?
(b)
How deep can it go before overflowing?
Check
A leaf function with a 3-instruction body is called 1000 times; each call adds 6 instructions (argument moves, jal, ret). The core runs at 48 MHz.
(a)
How many instructions do the calls run?
(b)
How long does that take?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
A function is entered with sp = 65536, makes a 16-byte frame, and saves ra at the top of it.
(a)
What is sp inside the function?
(b)
At what address is ra saved?
Check
A Q-format number has 12 fraction bits.
(a)
What integer stores 0.3?
(b)
What is its resolution, the value of one unit?
Check
0.55 and 0.6 are multiplied in Q15 with rounding: the product of the integers, plus , shifted right by 15.
(a)
What integer results?
(b)
What value does it represent?
Check
A compiler divides an unsigned 16-bit x = 9999 by 10 as (x × 52429) >> 19.
(a)
What is the product?
(b)
What does the shift leave?
Check
A 12-bit ADC with a 2500 mV reference reads 3001.
(a)
What does (c × V) >> N give, in mV?
Write units the way you normally would: 1.5 mV, 1500 µV and 0.0015 V are the same answer.
(b)
How much does dropping the fraction lose?
Check
100 Q15 values, each between −1 and 1, are summed in an integer accumulator.
(a)
How many guard bits above the 16 must it have so the sum can't overflow?
(b)
How wide must the accumulator be?
Check
Two loops count the 1 bits of x = 4097.
(a)
How many passes does the x & (x − 1) loop make?
(b)
How many does a loop make that tests the low bit and shifts right until x is 0?
Check
x = p->next->...->val follows 3 next pointers, then reads val; each load depends on the one before and takes 3 cycles.
(a)
How many loads does it make?
(b)
How many cycles do the loads take?
Check
−101 is divided by 2 to the power 1.
(a)
What does div give (rounding toward zero)?
(b)
What does srai by 1 give?
Check
Q31 numbers for 0.3 and 0.25 are multiplied with mulh, which keeps the high 32 bits of the 64-bit product.
(a)
Read as a Q30 number, what value does mulh return?
(b)
By how many bits must it be shifted left to be Q31 again?
Check
The naive recursive Fibonacci computes F(15).
(a)
How many calls does it make?
(b)
How many frames are live at the deepest point, with F(1) and F(0) returning without one?
Check
Main sums the squares of 1 to 20 by calling square each time. Each pass of its loop runs 6 instructions plus the 4 in square, after 4 to set up and 2 to finish. The core runs at 16 MHz.
(a)
How many instructions run, counting the final failed test?
(b)
How long does that take?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
An ecall at address 0x060C traps to a handler. Before its mret, what should the handler put in mepc so the program continues after the ecall?
Check
Finish the handler so it adds 100 to a0 and returns to the instruction after the ecall.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
A timer counts at 8 MHz. For an interrupt every 1 ms, how much should the handler add to TIMECMP each time?
Check
A timer interrupt fires every 100 instructions, and its handler runs 17 of them. What percentage of the processor's time goes to the handler?
Check
Entry takes 3 cycles and mret 3. A handler adjusts sp twice, saves and restores 4 registers and does 50 cycles of work, at 48 MHz.
(a)
How many cycles does each interrupt cost?
(b)
What share of the core does a 10 kHz interrupt rate use?
Check
The cause code is 7.
(a)
What's mcause for a machine-mode interrupt with that code?
(b)
And for an exception with the same code?
Check
ecall at 0x058C. mepc for the handler to return past it?
Check
12 MHz timer, a tick every 2 ms. TIMECMP step?
Check
A 22-instruction handler every 400 instructions. Share of time?
Check
mcause reads 80000007, an interrupt. What is its cause code, with the interrupt bit removed?
Check
A program writes 1 MB in chunks of 64 KB, one system call per chunk. Each call costs 300 cycles of overhead on a 3 GHz processor. How much time is overhead?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
A trap handler saves and restores 31 registers of 4 bytes, one memory instruction each, plus 80 cycles of other work. How many cycles does a trap cost at one cycle per memory instruction?
Check
A task makes 20000 system calls a second, each costing 102 cycles of overhead, on a 400 MHz processor. What percentage of the processor does that use?
Check
The starter installs a trap handler and makes a system call. Complete the handler so that it doubles a0 and returns to the instruction after the ecall.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
Model buffered output. A program emits n = 1000 messages whose lengths are rng.randrange(10, 200) bytes (rng = random.Random(seed)). Write calls_unbuffered(lengths) (one system call per message) and calls_buffered(lengths, B): copy messages into a buffer of B bytes and make one call each time the next message wouldn't fit (and one at the end if anything is left); a message longer than B gets its own call. Set u, b4k (with B = 4096) and ratio = u / b4k.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
What cause code is in mcause = 80000005?
Check
How long do 1000 system calls of 200 cycles take on a 3 GHz processor, in µs?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
How many bytes per second does a 19200-baud UART carry (1 start, 8 data, 1 stop bit)?
Check
A 160 MHz processor takes 11520 interrupts a second, each costing 40 cycles. What percentage of its time do they use?
Check
A main loop checks a button once every 5 ms.
(a)
What is the longest the program can take to notice a press?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
What is the average delay, for presses at random times?
Check
A converter delivers 48000 samples a second through DMA, in blocks of 64 samples with double buffering.
(a)
How many interrupts a second does the processor take?
(b)
How long does the processor have to finish each block?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
A bus moves 16 bits per transfer at 8 million transfers a second. What is its bandwidth?
Check
Read the switches (at 0x20004) and show them on the LEDs (at 0x20000) with the low four bits inverted.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
A UART at 1000000 baud (10 bits a byte) fills a 16-byte FIFO that interrupts at 12 bytes.
(a)
How long does the handler have before a byte is lost?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
(b)
How many interrupts a second?
Check
A 500 ksample/s ADC feeds a 100 MHz core; an interrupt costs 80 cycles.
(a)
What load does an interrupt per sample put on the core?
(b)
And DMA with an interrupt per block of 64?
Check
How long is one bit at 115200 baud?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
How long does a 10-byte message take at 9600 baud, 10 bit times a byte?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
1000 events a second, 50 cycles each, on a 72 MHz clock: what percentage load?
Check
A main loop of 6 instructions does a read-modify-write, and a tick arriving before any of 2 of them loses the handler's update. 1000 ticks arrive at random points.
(a)
What fraction of the handler's updates are lost?
(b)
About how many updates are lost?
Check
A 16 MHz core takes 6 cycles to enter a handler, and its longest critical section is 100 cycles.
(a)
What's the worst-case interrupt latency?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
(b)
And with no critical sections?
Check
head (at 0x1000) indexes an 8-word ring buffer buf (from 0x1004). Store a1 at buf[head], then advance head, wrapping from 7 to 0.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
A ring buffer of 16 slots has head = 1 and tail = 7: the head has wrapped around.
(a)
How many entries are waiting?
(b)
How many more can the handler add before it's full?
Check
A 2-instruction window in a 7-instruction loop. What share of ticks lose their update?
Check
16 MHz, 12-cycle entry, 60-cycle critical section. Worst-case latency?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
Ring buffer of 16, head 2, tail 12. Entries waiting?
Check
Two threads each increment a shared counter (starting at 0) 3 times using atomic amoadd.w. What is the final value?
Check
2 cores hammer one shared atomic counter. Every increment needs the cache line, which takes 100 ns to move between cores. About how many million increments per second happen in total?
Check
A contended spinlock takes 100 ns to acquire and protects 20 ns of work. What percentage of the time is spent in the critical section's work?
Check
Two threads each perform 4 unprotected increments (load, add, store) on a counter starting at 0. What's the smallest final value some interleaving can produce?
Check
8 cores could each do 100 million increments a second on private counters. By what factor does that beat one shared atomic counter whose cache line takes 100 ns per handoff?
Check
Enumerate every interleaving of two threads that each do k = 2 increments as two steps, a load into a private register and a store of that register plus one, to a shared counter starting at 0. Count the distinct schedules (total), how many give the correct 2*k (correct), and the smallest final value (worst). Use itertools.combinations to choose which of the steps belong to thread 0.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
About how many million updates per second can a shared atomic counter handle if each cache-line handoff takes 80 ns?
Check
A contended lock costs 60 ns to acquire and guards 30 ns of work. How many million critical sections per second complete?
Check
A firmware image has 30 kB of .text, 1 kB of .rodata, 2 kB of .data and 10 kB of .bss, and reserves 1 kB of stack.
(a)
How much flash does it need?
(b)
How much RAM does it need?
Check
What does auipc t0, 1 at address 1000 put in t0?
Check
la a0, buf sits at 0040, and buf is at 1800.
(a)
What immediate does the auipc hold?
(b)
What immediate does the addi hold?
Check
Startup code copies 2048 bytes of .data a word at a time, taking 5 cycles per word on a 48 MHz clock. How long does the copy take?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
Startup copies 400 bytes of .data (5 instructions a word) and zeroes 2000 bytes of .bss (3 a word) at 48 MHz.
(a)
How many instructions does that take?
(b)
How long, at one instruction a cycle?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
A map file lists .text 9000, .rodata 800, .data 900 and .bss 6000 bytes, with a 1024-byte stack.
(a)
How much flash does it use?
(b)
And how much RAM?
Check
8 kB of code, 1 kB of constants and 4 kB of initialized data: how much flash?
Check
1 kB of .data, 4 kB of .bss and 4 kB of stack: how much RAM?
Check
What does auipc t1, 2 at 0200 produce?
Check
The same program runs on processor A (CPI 1, 100 MHz) and on processor B (CPI 3, 450 MHz).
(a)
How many times faster is B than A? (A number below 1 means B is slower.)
(b)
What is B's rate in MIPS?
Check
A program's instructions are 0.5 ALU at 1 cycle, 0.2 loads at 5 cycles, and the rest branches at 2 cycles.
(a)
What is its average CPI?
(b)
What percentage of the cycles go to loads?
Check
A fraction 0.7 of a program's time is sped up by 2 times.
(a)
What is the overall speedup?
(b)
What is the largest speedup any improvement of that part could give?
Check
A fraction 0.75 of a program's time is in one routine. How many times faster must that routine get for the whole program to run 1.5 times faster?
Check
A new processor is 1.5, 2.5 and 1.1 times as fast as the old one on three benchmarks. What is the geometric-mean speedup?
Check
A microcontroller draws 50 mW at 16 MHz and averages a CPI of 2. How much energy does each instruction take?
Write units the way you normally would: 1.5 nJ, 1500 pJ and 0.0015 µJ are the same answer.
Check
Machine A: 2 GHz, CPI 1.2. Machine B: 3.5 GHz, CPI 2.5, running 0.8 times as many instructions.
(a)
How long does A take per instruction of its program?
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
(b)
What's B's speedup over A (below 1 if it's slower)?
Check
8 million instructions at CPI 1.2 on a 100 MHz clock: how long?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
A fraction 0.3 is sped up 3 times. Overall speedup?
Check
What is the MIPS rating at CPI 1.6 and 72 MHz?
Check
An unoptimized loop takes 14 instructions a pass; optimized, it takes 6. It runs 1000 passes.
(a)
How many instructions does optimization save?
(b)
By what factor does the loop speed up, at one instruction a cycle?
Check
A function with a 2-instruction body is called 1000 times, and each call costs 6 more instructions.
(a)
How many instructions do the calls run in all?
(b)
What share of that does inlining remove?
Check
Multiply a0 by 10 without mul, and put the result in a1.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
*a += *b; *a += *b; runs with a and b pointing at the same int, which holds 5.
(a)
What does the int hold afterward?
(b)
What would a compiler that loaded *b only once produce?
Check
A loop runs 1000 passes of a 3-instruction body, with 2 instructions of loop overhead per pass.
(a)
How many instructions does it run?
(b)
Unrolled by 8?
Check
12 instructions a pass before, 7 after, 500 passes. Instructions saved?
Check
What does (x << 2) + x give for x = 3?
Check
Inlining a 4-instruction function called 10000 times, at 5 instructions per call. Instructions saved?
Check
An interrupt costs 12 cycles of hardware entry, then its handler saves and restores 4 registers (one sw and one lw each), does 30 instructions of work and ends with mret. Interrupts arrive 20000 times a second on a 16 MHz processor.
(a)
How many cycles does each interrupt take?
(b)
What percentage of the processor's time do the interrupts use?
Check
A timer interrupt handler moves TIMECMP forward by 1000 cycles each time, on a 48 MHz clock.
(a)
How many interrupts a second does that give?
(b)
How long is it between interrupts?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
A device sends 20-byte messages over a 57600-baud UART.
(a)
How many bytes a second can the UART carry?
(b)
How long does one message take?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
Firmware polls a sensor's status register every 10 µs, each poll costing 20 cycles on a 32 MHz clock.
(a)
What percentage of the processor's time does polling use?
(b)
What is the worst-case delay before a new reading is noticed?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
An ADC delivers 500000 samples a second. Each interrupt costs 80 cycles on a 168 MHz processor.
(a)
With an interrupt per sample, what percentage load would that be? (Over 100% means impossible.)
(b)
With DMA in blocks of 128, what is the interrupt load?
Check
A DMA controller moves 64 kB over a 16-bit bus at 25 million transfers a second.
(a)
What is the bus bandwidth?
(b)
How long does the transfer take, using the whole bus?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
A build reports 28 kB of .text, 2 kB of .rodata, 3 kB of .data and 8 kB of .bss, with 1 kB set aside for the stack.
(a)
How much flash does it need?
(b)
How much RAM does it need?
Check
la t0, table is at 0080 and table is at 1388.
(a)
What is the auipc immediate?
(b)
What is the addi immediate?
Check
A program runs 10 million instructions on processor A (CPI 1.2, 80 MHz). Recompiled for processor B, it needs 0.8 as many instructions, at CPI 1.4 and 120 MHz.
(a)
How long does it take on A?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
How many times faster is B?
Check
A fraction 0.65 of a program's time is in a routine that gets 3 times faster.
(a)
What is the overall speedup?
(b)
What percentage of the new running time is spent outside the routine?
Check
Of a program's instructions, 0.45 are ALU (1 cycle), 0.25 are loads that hit in a cache (2 cycles) and the rest branches (1 cycle). A fraction 0.1 of the loads miss and take 50 extra cycles each.
(a)
What is the average CPI?
(b)
What MIPS rate does that give at 100 MHz?
Check
A microcontroller draws 40 mW at 16 MHz and averages CPI 1.5. A task runs 20 million instructions.
(a)
How long does the task take?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
(b)
How much energy does it use?
Check
A 48 MHz core takes 8 cycles to enter an interrupt handler; its longest critical section is 60 cycles.
(a)
What is the worst-case interrupt latency?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
(b)
How much of that is the critical section?
Check
A main loop of 6 instructions has a 2-instruction window between reading a shared counter and writing it back. 400 timer ticks, each adding to the counter in a handler, land at random points.
(a)
What share of the handler's updates are lost?
(b)
About how many updates are lost?
Check
Inlining removes the 6-instruction call overhead from a 4-instruction function called 10000 times on a 200 MHz core (one instruction a cycle).
(a)
How many instructions does it save?
(b)
How much time is that?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
A data logger on a 200 MHz processor makes 2000 system calls a second at 150 cycles of overhead each, and also updates a counter shared between two cores whose cache line takes 120 ns per handoff.
(a)
What percentage of one core goes to system-call overhead?
(b)
At most how many million times per second can the two cores together update the shared counter?
Check
A program runs 4 million instructions at an average CPI of 1.25 on a 120 MHz clock.
(a)
How long does it take?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
What is its MIPS rate?
Check
Consider addi x9, x0, 12 (opcode 0x13).
(a)
What is its encoding?
(b)
What is the word with only its immediate field filled in, everything else 0?
Check
The word DEADBEEF is stored at 0x2000 on this little-endian machine.
(a)
What byte is at 0x2000?
(b)
What does lb from 0x2003 load, as a signed number?
Check
A loop's branch at 1130 jumps back 4 instructions; elsewhere, jal ra, f at 1130 + 8 calls f at 1B58.
(a)
What offset does the branch hold?
(b)
What does the jal put in ra?
Check
struct sample { int t; short v; short flags; } is 8 bytes: t at offset 0, v at 4, flags at 6. An array of them starts at 1000.
(a)
At what address is s[3].v?
(b)
How far is s[3] from s[0]?
Check
A recursive function saves ra and 4 s registers in a frame rounded up to 16 bytes, and recurses 10 levels deep. sp starts at 0x10000.
(a)
How big is each frame?
(b)
What is sp at the deepest point?
Check
A control register holds 5B.
(a)
What does it hold after r ^= (1 << 0)?
(b)
What would r &= ~(1 << 0) give instead?
Check
0.55 and 0.25 are stored in Q15 and multiplied.
(a)
What integer stores 0.55?
(b)
The integer product is shifted right arithmetically by 15. What results?
Check
Signed integer division on RISC-V.
(a)
What does div give for −25 ÷ 2?
(b)
What does rem give for −25 and 2?
Check
Samples arrive at 48000 per second on a 96 MHz processor whose interrupts cost 50 cycles.
(a)
What load would an interrupt per sample put on it? (Over 100% means impossible.)
(b)
With DMA in double-buffered blocks of 512, how long does the processor have per block?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
Firmware has 22 kB of code, 3 kB of constants, 5 kB of initialized globals, 20 kB of zeroed globals and a 2 kB stack.
(a)
How much flash?
(b)
How much RAM?
Check
A fraction 0.8 of a program's time is in a routine made 4 times faster.
(a)
What is the overall speedup?
(b)
What is the most any speedup of that routine could give?
Check
A program is 0.5 ALU instructions (1 cycle), 0.2 loads (4 cycles) and the rest branches (3 cycles on average).
(a)
What is its CPI?
(b)
What percentage of its cycles go to branches?
Check
Add up the absolute values of the four signed words in vals and leave the total in a0.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
a0 holds a 10-bit ADC code; the reference is 2500 mV. Put the reading in millivolts in a1, rounded down.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
On RV32, a struct holds 3 chars, then a 4-byte field aligned to 4, then one more char.
(a)
At what offset does the 4-byte field start?
(b)
How big is the struct?
Check
A single-cycle processor has = 30, memory reads of 150, a register-file read of 120, an ALU of 180, a mux of 20 and register-file setup of 40 (all ps).
(a)
What is the minimum clock period?
Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.
(b)
What is the highest clock frequency?
Check
A single-cycle processor's clock period is 850 ps, set by lw, whose path includes a 150 ps data-memory read.
(a)
How long do 50 million instructions take?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
What percentage of each cycle does an add, which skips the data memory, spend idle?
Check
A designer replaces the 250 ps data memory of a 700 ps single-cycle processor with one 50 ps faster.
(a)
What is the new clock period, if lw is still the slowest?
Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.
(b)
How many times faster does every program run?
Check
A multi-cycle processor clocks at the memory's 200 ps plus 60 ps of overhead. Loads (25%) take 5 cycles, stores (15%) 4, branches (10%) 3 and everything else 4.
(a)
What's its CPI?
(b)
What's its average time per instruction?
Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.
Check
A single-cycle processor has = 30 ps, memories of 150 ps, a register-file read of 120 ps, an ALU of 180 ps, a multiplexer of 25 ps and a register-file setup of 40 ps.
(a)
What's the clock period, set by a load?
Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.
(b)
What share of the cycle does an add leave idle?
Check
= 30, memories 180, register read 110, ALU 150, mux 25, register setup 50 (ps): what is the single-cycle clock period?
Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.
Check
What clock frequency does an 800 ps period give?
Write units the way you normally would: 1.5 MHz, 1500 kHz and 0.0015 GHz are the same answer.
Check
How long do 2 million instructions take on a single-cycle processor with a 600 ps clock?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
An instruction word is 00C58533.
(a)
What's its opcode (bits 6:0)?
(b)
What do bits 11:7 hold, as a number?
Check
A microprogrammed control store holds 256 micro-instructions of 24 bits each.
(a)
How big is it?
(b)
How many address bits does its micro-PC need?
Check
What's the opcode of 00C58533?
Check
What's bit 30 of 00C58533?
Check
How big is a control store of 128 words of 32 bits?
Check
A program is 25% loads, 8% stores and 20% branches; the rest are R-type. The multi-cycle clock is 320 ps.
(a)
What's the CPI?
(b)
What's the average time per instruction?
Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.
Check
A multi-cycle datapath has = 30 ps, multiplexers of 25 ps, an ALU of 250 ps, a memory of 200 ps and a setup time of 40 ps.
(a)
What's the clock period?
Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.
(b)
How long does a load take?
Check
A loop body has 1 loads, 5 R-type instructions and one branch, and runs 100 times.
(a)
How many cycles does it take on the multi-cycle processor?
(b)
And on the single-cycle one?
Check
Adding instructions grows the control state machine to 13 states.
(a)
How many flip-flops does a binary state encoding need?
(b)
And a one-hot encoding?
Check
20% loads (5 cycles), 10% branches (3) and the rest 4 cycles. CPI?
Check
An instruction takes 4 cycles of 250 ps. How long is that?
Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.
Check
50 passes of 1 loads, 4 R-type instructions and a branch. Multi-cycle cycles?
Check
A single-cycle processor has = 30, memories of 150, a register-file read of 120, an ALU of 180, a multiplexer of 25 and a register-file setup of 40 ps.
(a)
What is the clock period?
Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.
(b)
What is the clock frequency?
Check
A 400 ps multiplier is added beside the 120 ps ALU of a 750 ps single-cycle processor, on the critical path. 3% of instructions multiply.
(a)
What is the new clock period?
Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.
(b)
By what factor does every program slow down, multiplies or not?
Check
An instruction word is 00A12423.
(a)
What is funct3 (bits 14:12)?
(b)
What is rs1 (bits 19:15)?
Check
An I-type instruction is C0028293.
(a)
What immediate does the immediate generator produce?
(b)
What is its opcode?
Check
A store instruction is FE742E23.
(a)
What is its offset? (S-type: bits 31:25 are imm[11:5], bits 11:7 are imm[4:0].)
(b)
Which register does it store (rs2)?
Check
li t0, DEADBEEF becomes lui t0, hi then addi t0, t0, lo, where addi sign-extends lo.
(a)
What is hi?
(b)
What is lo, as a signed number?
Check
A jal ra, −64 sits at address 1024.
(a)
What does ra receive?
(b)
Where does execution continue?
Check
A program is 25% loads, 8% stores, 20% branches and 4% jumps; the rest are R-type and I-type arithmetic. On the multi-cycle processor, loads take 5 cycles, branches 3 and the rest 4, at 250 ps a cycle.
(a)
What is the CPI?
(b)
What is the time per instruction?
Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.
Check
A multi-cycle datapath has = 30, multiplexers of 25, an ALU of 260, a memory of 250 and a setup of 40 ps.
(a)
What is the clock period?
Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.
(b)
How long does a branch take?
Check
A loop body of 1 loads, 4 R-type instructions and a branch runs 100 times. The multi-cycle clock is 320 ps; the single-cycle clock is 700 ps.
(a)
How long does the multi-cycle processor take?
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
(b)
And the single-cycle processor?
Check
A single-cycle processor runs at 750 ps; a multi-cycle design for the same instructions averages a CPI of 3.9.
(a)
Below what clock period would the multi-cycle design be faster?
Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.
(b)
Below what period would even its 5-cycle loads be no slower?
Check
A microprogrammed control unit has 512 micro-instructions of 32 bits.
(a)
How big is its control store?
(b)
How many bits does its micro-PC need?
Check
A multi-cycle control state machine has 12 states.
(a)
How many state flip-flops with binary encoding?
(b)
With one-hot?
Check
A beq at 512 with offset −12 compares two registers; Zero = 1.
(a)
What is the next PC?
(b)
What target did the branch adder compute, either way?
Check
A main decoder is built as a ROM addressed by the 7-bit opcode, with 32 output signals; an ALU decoder as a ROM addressed by ALUOp (2 bits), funct3 and funct7's bit 5, with 8 outputs.
(a)
How many bits does the main decoder ROM hold?
(b)
And the ALU decoder ROM?
Check
A cache hits in 1 ns, a miss costs 100 ns more, and 2% of accesses miss. What's the average access time?
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
Check
A direct-mapped cache holds 4 KiB in 16-byte lines, for 32-bit addresses.
(a)
How many offset bits?
(b)
How many index bits?
(c)
How many tag bits?
Check
A 5-stage pipeline with no stalls runs 19 instructions. How many cycles from the first fetch to the last write back?
Check
On a 5-stage pipeline, 25% of instructions are loads, and half of those are followed at once by an instruction that uses the loaded value (1 stall cycle each). 10% are branches, and 40% of those are mispredicted (2 cycles lost each). What's the average CPI?
Check
A cache hits in 1 ns and a miss costs 40 ns.
(a)
What's the largest miss rate that keeps the average at 5 ns?
(b)
What's the average at a 1% miss rate?
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
Check
A direct-mapped 16 KiB cache has 16-byte lines and 32-bit addresses.
(a)
How many offset bits?
(b)
How many index bits?
(c)
How many tag bits?
Check
Hit 1 ns, penalty 120 ns, miss rate 1%. AMAT?
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
Check
70 instructions through a 5-stage pipeline, no stalls. Cycles?
Check
Index bits for an 8 KiB direct-mapped cache with 16-byte lines?
Check
15% loads (half followed by a use: 1 stall), 12% branches (30% mispredicted: 2 cycles). CPI?
Check
A 5-stage pipeline with no stalls runs 100 instructions.
(a)
How many cycles does it take?
(b)
How many instructions finish per cycle, on average?
Check
A pipeline's slowest three stages take 150, 180 and 200 ps (the others less), and each pipeline register adds 50 ps.
(a)
What is the clock period?
Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.
(b)
What is the clock frequency?
Check
0.2 of a program's instructions are loads, 0.3 of which are used immediately; 0.2 are branches, 0.6 of which are mispredicted at a 2-cycle penalty.
(a)
What is the CPI?
(b)
What percentage of the cycles are lost to mispredictions?
Check
A processor's 800 ps of logic is split into 10 equal stages, each with a 30 ps register, and there are no stalls.
(a)
What is the cycle time?
Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.
(b)
How many times the single-cycle throughput (with one register) is that?
Check
Without forwarding, 30% of instructions wait 2 cycles for the one before. With forwarding only load-use pairs stall 1 cycle: 20% loads, 50% of them used at once.
(a)
What's the CPI without forwarding?
(b)
And with it?
Check
How many cycles do 10 instructions take in a 5-stage pipeline with no stalls?
Check
The slowest stage takes 180 ps and the pipeline register adds 25 ps. What is the cycle time?
Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.
Check
Loads 0.15 (used at once 0.4 of the time), branches 0.2 (taken 1 of the time, predicted not taken, 2-cycle penalty): what is the CPI?
Check
A loop of 8 iterations is run 100 times; count only the runs after the first.
(a)
How many times does a 1-bit predictor mispredict its closing branch in those runs?
(b)
What accuracy does a 2-bit predictor achieve on it?
Check
Branches are 0.2 of the instructions, predicted with accuracy 0.85, and a misprediction costs 20 cycles. The base CPI is 1.
(a)
What is the CPI?
(b)
What is the IPC?
Check
A 2-wide superscalar processor loses 0.1 cycles per instruction to stalls and mispredictions.
(a)
What is its CPI?
(b)
What IPC does it achieve?
Check
A fraction 0.9 of a program's work runs in parallel on 4 cores.
(a)
What is the speedup over one core?
(b)
What fraction of the cores' capacity is used, as a percentage?
Check
A chip replaces one core with 2 cores, each at 0.6 of the clock rate and 0.9 of the voltage.
(a)
What is the dynamic power relative to the single core?
(b)
What is the throughput on perfectly parallel work, relative to the single core?
Check
90% of a program runs in parallel on 4 cores.
(a)
What's the speedup?
(b)
How efficiently are the cores used?
Check
A loop of 5 iterations is run many times.
(a)
What accuracy does a 1-bit predictor get on its closing branch?
(b)
And a 2-bit predictor?
Check
What accuracy does a 1-bit predictor get on the closing branch of a 16-iteration loop that is run repeatedly?
Check
B = 0.1, accuracy 0.9, penalty 15 cycles, base CPI 1: what is the CPI?
Check
A fraction 0.75 parallel on 2 cores: what is the speedup?
Check
A fraction 0.8 of a program's time vectorizes perfectly onto 4 lanes. What's the overall speedup?
Check
A strip-mined vector loop processes 101 elements, at most 8 per iteration. How many iterations does it run?
Check
A loop moves 8 bytes of memory per element and does 8 floating-point operations per element. With 25 GB/s of memory bandwidth, what's the most it can compute, in billions of operations per second?
Check
a0 and a1 each hold four packed bytes. Put their lane-by-lane sums (each modulo 256) in a2, without letting carries cross between bytes.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
Write two SWAR functions for 32-bit words: add_bytes(a, b), lane-wise byte addition modulo 256 using the masking trick, and has_zero_byte(x) returning True if any byte of x is zero, using . Keep results in 32 bits. They'll be checked against byte-by-byte references on random words from random.Random(seed).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A fraction 0.75 vectorizes onto 2 lanes. What's the speedup?
Check
A vector loop with 8-element vectors processes 500 elements. How many does its last, partial iteration handle?
Check
A single-cycle processor's units take: register clock-to-Q 30, each memory 160, register-file read 130, ALU 170, result mux 25, register-file setup 45 (all ps).
(a)
What is the clock period?
Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.
(b)
What percentage of the cycle does an R-type instruction, which skips the data memory, actually need?
Check
A slow unit of 400 ps is added in parallel with the 120 ps ALU of a 700 ps single-cycle processor, on the critical path. A fraction 0.1 of instructions use it.
(a)
What is the new clock period?
Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.
(b)
By what factor does every program slow down, however few instructions use the unit?
Check
A cache hits in 1 cycles and misses 0.02 of the time, with a 100-cycle miss penalty.
(a)
What is the average memory access time?
(b)
A larger cache with the same hit time misses only 0.015 of the time. By what factor does the AMAT improve?
Check
A direct-mapped cache holds 16 KiB in 16-byte lines, for 32-bit addresses.
(a)
How many offset bits?
(b)
How many tag bits?
Check
A single-cycle design with 1000 ps of logic and a 40 ps register is pipelined into 6 equal stages, each adding a 40 ps register. It runs 50 instructions with no stalls.
(a)
How many cycles does the pipeline take?
(b)
How many times faster than the single-cycle design is it on these instructions?
Check
A five-stage pipeline's stages take 170, 200, 150, 200 and 150 ps, and each pipeline register adds 55 ps.
(a)
What is the clock period?
Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.
(b)
What is the clock frequency?
Check
0.2 of instructions are loads, 0.25 of which are used by the very next instruction; 0.18 are branches, 0.7 of them taken, predicted not taken at a 2-cycle penalty. Forwarding is complete.
(a)
What is the CPI?
(b)
What percentage of the stall cycles come from load-use hazards?
Check
An inner loop of 6 iterations runs 50 times; ignore the first run.
(a)
What accuracy does a 1-bit predictor reach on the loop's closing branch?
(b)
How many mispredictions does a 2-bit predictor make in the counted runs?
Check
Design X has a short pipeline: 400 ps cycle, 2-cycle misprediction penalty. Design Y is deeper: 250 ps cycle, 14-cycle penalty. Branches are 0.2 of instructions, predicted with accuracy 0.9; the base CPI is 1.
(a)
What is X's time per instruction?
Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.
(b)
How many times faster is Y than X?
Check
A 3-wide superscalar processor loses 0.05 cycles per instruction to stalls.
(a)
What is its CPI?
(b)
What fraction of the CPI of a 1-wide design with the same stalls is that?
Check
A fraction 0.85 of a job runs in parallel on 2 cores.
(a)
What is the speedup over one core?
(b)
What is the most any number of cores could give?
Check
A chip uses 4 cores at 0.5 of the original clock and 0.85 of the voltage, in place of one fast core.
(a)
What is its dynamic power relative to the single core?
(b)
How many times the single core's work per joule does it do on parallel work?
Check
Without forwarding, 30% of instructions stall 2 cycles for the one before. With forwarding, only loads (20%) used at once (50% of them) stall 1 cycle.
(a)
What is the CPI without forwarding?
(b)
How many times faster does forwarding make it?
Check
800 ps of logic is split into 5 equal stages, each with 40 ps of register overhead.
(a)
What is the clock period?
Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.
(b)
What is the speedup at a CPI of 1?
Check
15% of instructions are branches, predicted with 85% accuracy; a misprediction costs 10 cycles.
(a)
What is the CPI, with no other stalls?
(b)
What share of cycles are lost to mispredictions?
Check
A fraction 0.85 of a program vectorizes onto 4 lanes, and its hot loop handles 1000 elements.
(a)
What's the overall speedup?
(b)
What's the most any vector width could give?
Check
A 32 KiB, 8-way set-associative cache has 32-byte lines; addresses are 32 bits.
(a)
How many sets?
(b)
How many index bits?
(c)
How many tag bits?
Check
L1 hits in 1 cycles and misses 0.03 of the time; L2 hits in 15 cycles and misses 0.4 of the accesses that reach it; memory takes 80 cycles.
(a)
What is the AMAT?
(b)
How many times better is that than L1 alone with memory behind it?
Check
A loop reads every element of an array of 1000 elements of 1 bytes, aligned to a line, once, through a cache with 64-byte lines that starts empty.
(a)
How many misses?
(b)
What is the miss rate?
Check
A cache has 256 sets of 16-byte lines. Which set does address 74565 map to, and at what offset?
(a)
Which set?
(b)
What offset within the line?
Check
A loop stores to the same word 100 times, and the line is evicted afterward.
(a)
How many memory writes does a write-through cache make?
(b)
How many line write-backs does a write-back cache make?
Check
L1 hits in 1 cycle and misses 5%; L2 takes 8 cycles and misses 40% of what reaches it; memory takes 150.
(a)
What's the AMAT in cycles?
(b)
What fraction of all accesses go to memory?
Check
A 32 KiB, 2-way cache has 64-byte lines and 32-bit addresses.
(a)
How many index bits?
(b)
How many tag bits?
Check
How many index bits does a 16 KiB, 4-way cache with 32-byte lines use?
Check
L1: 1 cycles, 0.04 misses; L2: 20 cycles, 0.5 local misses; memory 100 cycles. What is the AMAT?
Check
How many misses does reading 512 elements of 2 bytes once, sequentially and line-aligned, cause with 64-byte lines?
Check
A loop stores 4096 words (4 bytes each) into a fresh array, once each, with 32-byte lines.
(a)
How many bytes reach memory through a write-through, no-allocate cache?
(b)
And through a write-back, write-allocate cache?
Check
A program is 20% stores; memory accepts one write every 8 cycles through a write buffer.
(a)
How many stores per cycle would it issue at one instruction a cycle?
(b)
What's the lowest CPI the memory allows once the buffer is full?
Check
A write-back cache misses 5% of the time with a 50-cycle penalty, and 20% of evicted lines are dirty. Hits take 1 cycle.
(a)
What's the average miss penalty without a write buffer?
(b)
What's the AMAT?
Check
A DMA controller fills a 1500-byte receive buffer, and the cache has 32-byte lines.
(a)
How many lines must be invalidated if the buffer starts on a line boundary?
(b)
And if it starts 20 bytes into a line?
Check
4000 words stored once through a write-back, write-allocate cache. Bytes moved?
Check
12% stores, 10 cycles per memory write. Lowest CPI once the buffer fills?
Check
How many 32-byte lines does an aligned 512-byte DMA buffer cover?
Check
A 32 KiB, 2-way set-associative cache has 64-byte lines.
(a)
How many index bits?
(b)
How many tag bits?
Check
L1 hits in 1 cycle and misses 4%; L2 takes 10 cycles and misses 40% of what reaches it; memory takes 200 cycles.
(a)
What is the AMAT?
(b)
What would it be without the L2?
Check
A loop stores to every word of a freshly allocated 32-byte line 6 times before it's evicted.
(a)
How many bytes does write-through send to memory?
(b)
How many does write-back with allocation move?
Check
A program is 20% stores through a write-through cache; the write buffer drains one store every 6 cycles.
(a)
How many stores per cycle can memory take?
(b)
What is the lowest CPI the stores allow, once the buffer is full?
Check
A write-back cache misses 5% of the time; a miss takes 80 cycles, plus 80 more if the evicted line is dirty, which 25% are. Hits take 1 cycle.
(a)
What is the average miss penalty?
(b)
What is the AMAT?
Check
A DMA receive buffer of 1500 bytes, with 32-byte cache lines.
(a)
How many lines must be invalidated if it starts on a line boundary?
(b)
And if it starts 24 bytes into a line?
Check
A direct-mapped 32 KiB write-back cache with 32-byte lines; each line keeps a tag, a valid bit and a dirty bit, for 32-bit addresses.
(a)
How many tag bits per line?
(b)
How many bits of tags, valid and dirty bits are there in all?
Check
A cache hits in 1 cycle(s) with a 50-cycle miss penalty.
(a)
What miss rate gives an AMAT of 4 cycles?
(b)
What hit rate is that?
Check
A processor with a base CPI of 1 makes 1.2 memory accesses per instruction; 1% miss, costing 100 cycles each.
(a)
What is its CPI?
(b)
What share of its time goes to memory stalls?
Check
Two cores each increment their own counter 1000 times, taking turns. The counters share one 64-byte line.
(a)
How many writes miss, with a write-invalidate protocol?
(b)
How many miss if each counter is padded into its own line?
Check
A memory has 40 ns of latency and then delivers 8 bytes per ns.
(a)
What is the miss penalty for 64-byte lines?
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
(b)
And for lines twice as long?
Check
A loop stores 1000 words, once each, into a fresh array, with 32-byte lines.
(a)
How many bytes cross the bus with write-through, no-allocate?
(b)
And with write-back, write-allocate?
Check
L1 misses 5% of accesses, and L2 misses 10% of the accesses that reach it.
(a)
What share of all accesses go to memory?
(b)
What share reach L2?
Check
A loop touches 4 arrays in turn, all mapping to the same set of a 2-way LRU cache.
(a)
After the first round, how many misses does each round of 4 accesses take?
(b)
And in a direct-mapped cache?
Check
An n × n matrix of ints, n = 100, is summed row by row through a cache with 32-byte lines.
(a)
How many lines does it touch?
(b)
What fraction of accesses miss, if nothing was cached before?
Check
A program uses virtual address 01312D00, with 4 KiB pages.
(a)
What is its virtual page number?
(b)
What is its page offset?
Check
A virtual page maps to physical page 01001, and the page offset is A2C. What physical address results (4 KiB pages)?
Check
A machine has 36-bit virtual addresses, pages of bytes and 8-byte page-table entries.
(a)
How many pages does a single-level table have to describe?
(b)
How big is that table, in MiB?
Check
A TLB answers in 1 cycle and hits 0.99 of the time. Memory takes 60 cycles and the page table has 4 levels.
(a)
What is the average time per access?
(b)
How many times faster is that than walking the table on every access?
Check
A TLB has 64 entries, and pages are 4 KiB.
(a)
What is the TLB's reach?
(b)
How many different pages can a loop touch over and over without a TLB miss, at most?
Check
An access normally takes 100 ns, but 10 in a million accesses page-fault, costing 5 ms each. What is the average access time?
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
Check
Virtual addresses have 32 bits, pages are 4 KiB and entries 4 bytes.
(a)
How big is a flat page table?
(b)
How many entries fit in one page?
Check
A TLB hits 99% of the time in 1 cycle; memory takes 60 cycles and the page table has 4 levels.
(a)
What's the average access time?
(b)
And with no TLB?
Check
What is the virtual page number of 007D0000 with 4 KiB pages?
Check
Physical page 0012C, offset 040: what physical address?
Check
What is the reach of a 64-entry TLB with 4 KiB pages?
Check
A DDR channel makes 3200 million transfers a second, 32 bits wide.
(a)
What's its peak bandwidth?
(b)
How many transfers does a 64-byte line take?
Check
A DRAM has CL = tRCD = tRP = 13.75 ns. 40% of accesses are row hits; the rest are row conflicts.
(a)
What does a row conflict cost to the first data?
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
(b)
What's the average?
Check
Flash takes 40 ns per read, and the core runs at 48 MHz.
(a)
How many cycles does a read take?
(b)
How many wait states is that?
Check
On a chip whose address decoder uses bits 31:28 to pick the region, an access goes to 20001000.
(a)
Which region number (0 to 15) does it select?
(b)
What's its offset within the region?
Check
A channel delivers 25.6 GB/s with 60 ns of latency and 64-byte lines.
(a)
How many misses must be in flight to use it fully?
(b)
What share of the bandwidth does one miss at a time use?
Check
Peak bandwidth of 3200 MT/s on a 64-bit channel?
Check
Flash of 30 ns at 64 MHz: how many wait states?
Check
20 GB/s, 70 ns, 64-byte lines: misses in flight needed?
Check
A trace of 4 instructions has one load-use pair and one taken branch. How many cycles does the five-stage pipeline take?
Check
A branch's outcome alternates taken, not taken, for 5 pairs. How many times does a 2-bit counter that starts at 1 mispredict it?
Check
A 4 KiB array is swept 5 times through a bigger cache with 32-byte lines. How many misses?
Check
5 instructions with 1 load-use pairs and 3 taken branches: how many pipeline cycles?
Check
A 10-iteration loop is run 3 times. How many times does a 2-bit counter starting at 1 mispredict its closing branch?
Check
A 64 KiB, 8-way cache has 32-byte lines.
(a)
How many index bits?
(b)
How many tag bits?
Check
A cache has 512 sets of 32-byte lines. A load reads address 123456.
(a)
Which set does it use?
(b)
What tag value is stored for it?
Check
L1: 1 cycles, 0.02 miss rate. L2: 14 cycles, local miss rate 0.5. Memory: 100 cycles.
(a)
What is the AMAT?
(b)
What percentage of all accesses go to memory?
Check
A processor has a base CPI of 1, makes 0.25 data accesses per instruction (plus one instruction fetch, which always hits), and its data cache misses 0.05 of the time with a 150-cycle penalty.
(a)
What is the CPI including data misses?
(b)
What percentage of the cycles are spent waiting for misses?
Check
A loop reads all 2000 elements of a 2-byte array in order, 10 times. The array is line-aligned and the cache, much larger than the array, starts empty with 64-byte lines.
(a)
How many misses?
(b)
What is the miss rate over all the reads?
Check
A loop stores to 4 different words of the same 64-byte line, 20 times each, then the line is evicted.
(a)
How many writes reach memory with a write-through cache?
(b)
How many line write-backs with a write-back cache?
Check
A program touches virtual address 0471C588, with 4 KiB pages.
(a)
What is the virtual page number?
(b)
What is the offset?
Check
A virtual page is mapped to physical page 001F2; the access is at offset 010 in a 4096-byte page.
(a)
What is the physical address?
(b)
What are its low 12 bits?
Check
A machine has 39-bit virtual addresses, -byte pages and 8-byte page-table entries.
(a)
How many bits is the virtual page number?
(b)
A single-level table would be bytes. What is x?
Check
A 1-cycle TLB hits 0.97 of the time; memory takes 80 cycles; the page table has 4 levels.
(a)
What is the average access time?
(b)
What percentage of that time is page-table walking?
Check
A TLB has 128 entries and pages are 4 KiB.
(a)
What is its reach?
(b)
How many 4 KiB pages' worth of memory is that?
Check
The lab's fully associative LRU cache has 8 KiB in 64-byte lines. A loop reads every word of a 17 KiB array, 5 times.
(a)
How many misses?
(b)
How many lines does the array span?
Check
A TLB hits 99.5% of the time in 1 cycle; a miss walks a 3-level page table in memory (80 cycles per access) before the data access.
(a)
How many memory accesses does a TLB miss add?
(b)
What is the average access time, with the data in memory?
Check
A loop sweeps 24 KiB repeatedly through a fully associative LRU cache of 16 KiB with 64-byte lines.
(a)
After the first pass, how many misses does each pass take?
(b)
How many does the first pass take?
Check
A DDR channel makes 1600 million transfers a second over 64 bits; CL = tRCD = tRP = 13.75 ns, and 80% of accesses hit an open row (the rest conflict).
(a)
What is its peak bandwidth?
(b)
What is the average time for a 64-byte line, latency plus burst?
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
Check
Address 74565 in a cache with 16-byte lines and 256 sets. Which set?
Check
A memory interface makes 3200 million transfers a second over 64 bits.
(a)
What is its peak bandwidth?
(b)
How long does a 128-byte line take to stream out?
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
Check
DRAM timings are CL = tRCD = tRP = 13.75 ns. 30% of accesses hit an open row, 20% go to an idle bank, and the rest are row conflicts.
(a)
What is the average time to first data?
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
(b)
What does a conflict cost?
Check
Flash takes 35 ns per read on a 64 MHz core.
(a)
How many wait states does it need?
(b)
Without a prefetch buffer, how many cycles does each instruction fetch take?
Check
A channel gives 25.6 GB/s with 60 ns of latency, moving 128-byte lines.
(a)
How many misses must be in flight to use it fully?
(b)
What bandwidth does one miss at a time get?
Check
A loop has 64 independent cache misses of 100 ns each; the core can have 4 outstanding at once.
(a)
About how long do they take?
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
(b)
And one at a time, as in pointer chasing?
Check
A TLB has 64 entries and pages are 4 KiB.
(a)
What is its reach, the memory it can map at once?
(b)
And with 2 MiB huge pages?
Check
Memory takes 100 ns; a page fault takes 5 ms to service. 10 accesses in a million fault.
(a)
What is the effective access time?
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
(b)
At most how many faults per million accesses keep the slowdown under 10%?
Check
A process on a 32-bit machine with 4 KiB pages and a two-level table (10, 10, 12 bits, 4-byte entries) has 12 MiB of code and data from address 0, and 1 page(s) of stack at the top.
(a)
How many page-table pages does it need?
(b)
How much memory is that?
Check
A virtual address has 36 bits, and pages are bytes with p = 12.
(a)
How many virtual pages are there?
(b)
How big would a flat table of 8-byte entries be?
Check
Virtual address 00103000 is in a page mapped to physical page number 498, with 4 KiB pages.
(a)
What is the page offset?
(b)
What is the physical address?
Check
A direct-mapped 4 KiB cache with 64-byte lines holds an R × R int matrix, R = 128, summed by columns.
(a)
How many different sets does one column use?
(b)
How many rows share each of those sets?
Check
A program streams through memory in 32-byte accesses; DRAM rows are 2048 bytes, and nothing else uses the bank.
(a)
What fraction of accesses hit the open row?
(b)
How many accesses are made per row?
Check
A DMA stream moves 50 MB/s over a bus that carries 200 MB/s.
(a)
What share of the bus does it use?
(b)
How much is left for the processor?
Check
A flash interface fetches 128 bits (four instructions) per read, with 2 wait state(s). Taken branches, one every 5 instructions, flush the prefetch buffer.
(a)
How many cycles does one flash read take?
(b)
What is the CPI, if each taken branch stalls for the wait states and straight-line code runs at one a cycle?
Check
Two streams in the same DRAM bank alternate accesses, each 32 accesses long; their rows differ. Timings are CL = tRCD = tRP = 14 ns.
(a)
How many accesses hit an open row?
(b)
How long do the accesses wait for data in all?
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
Check
What sign-extended I immediate does the addi word 80000013 hold?
Check
The emulator's pc is 0040. Which index of the words list holds the instruction to fetch?
Check
Sign-extend the 12-bit field value 4095.
Check
A jal ra, f at address 0028 runs. What does ra hold?
Check
What does (w >> 7) & 31 give for 00500513?
Check
A program runs 5 million instructions. A single-cycle processor runs it at 50 MHz. A 5-stage pipelined version of the same processor runs at 200 MHz with an average CPI of 1.5.
(a)
How long does the single-cycle processor take?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
How long does the pipelined processor take?
(c)
How many times faster is the pipelined processor?
Check
An array of 21 ints (4 bytes each) starts at 0x1578, and lesson 17's sum adds it up on a processor with CPI 1 at 100 MHz.
(a)
At what address does the last element start?
(b)
How many instructions does sum run (7 per pass, plus 5)?
(c)
How long does it take?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
sp holds 0xADF0 when f is called. f makes a 16-byte frame and saves ra at 12(sp), then calls g, which does the same and calls h, a leaf that makes no frame.
(a)
What does sp hold while h runs?
(b)
At what address did f save its ra?
Check
An 8-bit LED register holds 0x29. Firmware sets bit 1, then flips all eight bits with an XOR.
(a)
What does it hold after setting bit 1?
(b)
What does it hold after the XOR with 0xFF?
Check
A timer counting at 16 MHz interrupts a processor every 1 ms. The handler runs 64 instructions on a 150 MHz core with CPI 1.
(a)
How much does the handler add to TIMECMP each time?
(b)
How long does the handler take?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
(c)
What percentage of the processor's time does it use?
Check
A direct-mapped cache holds 8 KiB in 32-byte lines. It hits in 2 ns, misses cost 60 ns more, and 4% of accesses miss.
(a)
How many lines does it have?
(b)
How many index bits?
(c)
What's the average access time?
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
Check
Count how many of the five words in vals are negative, and leave the count in a0.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
A five-stage pipeline at 500 MHz: 0.2 of instructions are loads, 0.3 of them used at once; 0.2 are branches, 0.1 of them mispredicted at 2 cycles; 0.3 of instructions access data, missing 0.02 of the time at 40 cycles.
(a)
What is the CPI?
(b)
How long do a billion instructions take?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
Check
Encode sw x10, 8(sp) (S-type: opcode 0x23, funct3 2, rs1 = x2).
(a)
What goes in bits 11:7?
(b)
What is the whole word?
Check
Virtual address 004C4B40 is on a page that maps to physical page 0012C (4 KiB pages). The TLB hits 0.995 of the time in 1 cycle; memory takes 100 cycles and the page table has 2 levels.
(a)
What physical address does it become?
(b)
What is the average time per access?
Check
A UART receives continuously at 115200 baud (10 bit times a byte) into a FIFO that interrupts the 72 MHz processor once every 4 bytes, each interrupt costing 100 cycles plus 5 cycles per byte moved.
(a)
How many interrupts a second?
(b)
What percentage of the processor does receiving use?
Check
A smoothing filter runs y = y + ((a * (x - y)) >> 15) in Q15, with a = 8192, y starting at 0 and every input x = 10000.
(a)
What is y after the first sample?
(b)
What is y after the second?
Check
A pipelined core: 20% loads, 40% of them used at once (1-cycle stall); 15% branches, mispredicted 10% of the time (2 cycles); 1.3 memory accesses per instruction, 2% missing at 100 cycles.
(a)
What is the CPI?
(b)
What share of the cycles are memory stalls?
Check
A 100 ksample/s ADC feeds a 160 MHz core. An interrupt costs 80 cycles.
(a)
What load does an interrupt per sample put on the core?
(b)
And DMA with an interrupt per 64 samples?
Check
The instruction 00C58533 runs with a1 = 50 and a2 = 90.
(a)
What is bit 30, which chooses between add and sub?
(b)
What does a0 receive?
Check
Encode the R-type instructions below (opcode 0x33).
(a)
sub x12, x5, x11 (funct3 0, funct7 0x20)
(b)
mul x12, x5, x11 (funct3 0, funct7 1)
Check
The word FF010113 is an addi.
(a)
Which register does it write?
(b)
What is its immediate?
Check
The word 9ABCDEF0 is stored at 0x3000, little-endian.
(a)
What byte is at 0x3001?
(b)
What does lh from 0x3002 load?
Check
A recursive function saves ra and 2 s registers in a frame rounded up to 16 bytes and recurses 8 levels deep.
(a)
How much stack does it use at the deepest point?
(b)
How much would a loop version, with one such frame, use?
Check
Fixed point: 0.45 in Q15, and a 12-bit ADC reading of 1327 with a 5000 mV reference.
(a)
What integer stores 0.45?
(b)
What does multiply-then-shift give for the reading, in millivolts?
Write units the way you normally would: 1.5 mV, 1500 µV and 0.0015 V are the same answer.
Check
A peripheral produces 200000 values a second. Interrupts cost 40 cycles on a 120 MHz core.
(a)
What load would one interrupt per value cause? (Over 100% is impossible.)
(b)
With double-buffered DMA blocks of 1024, how long may processing a block take?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
A firmware build has 40 kB of .text, 5 kB of .rodata, 6 kB of .data, 30 kB of .bss and a 4 kB stack.
(a)
How much flash?
(b)
How much RAM?
Check
A fraction 0.8 of a program's time is in code made 3 times faster.
(a)
What is the overall speedup?
(b)
What is the limit as s grows?
Check
A single-cycle processor has clock-to-Q 35, memories 180, register read 140, ALU 200, mux 30 and register setup 50 (ps). A pipelined version's slowest stage is one memory access, plus 40 ps of register overhead.
(a)
What is the single-cycle clock period?
Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.
(b)
How many times faster is the pipelined clock?
Check
0.2 of instructions are loads, 0.3 of them used at once; 0.2 are branches, predicted with accuracy 0.97, at a 2-cycle penalty.
(a)
What is the CPI?
(b)
What is the IPC?
Check
A loop of 8 iterations runs 20 times; count all runs, the predictors starting at not taken (1-bit) and weakly not taken (2-bit).
(a)
How many mispredictions does the 1-bit predictor make?
(b)
How many does the 2-bit counter make?
Check
A 32 KiB, 4-way L1 with 64-byte lines hits in 2 cycles and misses 0.05 of the time; L2 takes 12 cycles with a local miss rate of 0.25; memory takes 150 cycles.
(a)
How many tag bits does the L1 use (32-bit addresses)?
(b)
What is the AMAT?
Check
Address 03938700 is on a page mapped to physical page 002BC (4 KiB pages). A 1-cycle TLB hits 0.999 of the time, memory takes 100 cycles, and the page table has 4 levels.
(a)
What is the physical address?
(b)
What is the average access time?
Check
4 cores at 0.6 of a single core's clock and 0.9 of its voltage run a program that is 0.99 parallel.
(a)
What is their dynamic power relative to the one core?
(b)
What is the speedup over the one core?
Check
Leave the largest of the five words in vals minus the smallest (the range) in a0.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
A program is 20% loads and 10% branches. A multi-cycle processor (loads 5 cycles, branches 3, the rest 4) runs at 320 ps; a single-cycle one at 800 ps.
(a)
What is the multi-cycle time per instruction?
Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.
(b)
What clock period would the multi-cycle design need to match the single-cycle one?
A kind of problem counts as solid once you've got it right on the first try twice in a row. Back to C8