This comprehensive study guide encompasses the foundational curriculum introduced during Weeks 01-07, aligning intimately with Chapters 1 and 2 of the formal textbook.
To best prepare for the Midterm Examination, students must be capable of bridging physical mathematics (latency, clock cycles) with logic design (K-Maps, Boolean Expansion), and software compilation (C arrays mapped to raw MIPS Machine Code).
Problem: Our favorite program runs in 25 seconds on $Computer_A$, which has a 2 GHz clock. We are trying to help a computer designer build a $Computer_B$, which will run this program in 5 seconds. The designer has determined that a substantial increase in the clock rate is possible, but this increase will affect the rest of the CPU design, causing $Computer_B$ to require 1.2 times as many clock cycles as $Computer_A$ for this program. What clock rate should we tell the designer to target?
Solution:
Problem: A compiler designer is trying to decide between compiling two specific hardware code sequences. They evaluate three unique instruction architectures: | Metric | Class A | Class B | Class C | | — | — | — | — | | Hardware CPI | 1 | 2 | 3 |
Which code sequence executes the most instructions? Which will be faster? What is the CPI for each sequence?
Solution:
$t0-$t9 (temporary), $s0-$s7 (saved across calls), $a0-$a3 (arguments), $v0-$v1 (return values), $ra (return address), $sp (stack pointer).
$s0-$s7 must be structurally saved/restored by the callee if modified, whereas $t0-$t9 are caller-saved..data: Physical memory section for declaring global data and static variables in RAM..text: Executive section for code instructions. The main: label designates the mainline execution entry point.opcode(6) | rs(5) | rt(5) | rd(5) | shamt(5) | funct(6)
opcode is inherently 0; funct dictates the exact physical operation to route to the ALU. shamt determines the shift amount.opcode(6) | rs(5) | rt(5) | immediate(16)
opcode(6) | address(26)
$sp):
$sp downward (addi $sp, $sp, -X), store any utilized $s0-$s7 registers out of harm’s way, execute logical manipulations, pop them back symmetrically, and structurally return using jr $ra.jal (Jump and Link) permanently overwrites $ra with a new return address, a nested procedure must save its primary $ra physically onto the stack. After the internal jal concludes, it carefully restores that original $ra off the stack before finalizing its own return via jr $ra.Problem: Determine the two’s complement constraint integer for the raw binary address 11100111.
Solution:
(Note: This concept is mathematically critical for understanding MIPS Branch offsets and calculating Signed Immediate addresses).
0001100000011001 (representing 25 decimal).Problem: Convert the following MIPS instruction into its corresponding 32-bit hexadecimal machine code representation: lw $t1, -4($s3)
Solution:
opcode rs rt immediate)lw opcode: 0x23 or $35$ decimal (100011 binary)rs (base register): $s3 maps to array register $19$ (10011 binary)rt (destination register): $t1 maps to array register $9$ (01001 binary)immediate: The integer -4 written mathematically in 16-bit two’s complement.
0000 0000 0000 0100 -> Invert to: 1111 1111 1111 1011 -> Add 1: 1111 1111 1111 1100 (0xFFFC)100011 | 10011 | 01001 | 1111 1111 1111 11001000 1110 0110 1001 1111 1111 1111 1100
0x8E69FFFCProblem: Consider the C language declaration char x[8][3];. If x[0][2] happens to be stored at memory address 0x20c, at which memory address would x[2][1] physically be stored? Assume little-endian memory and row-major array storage methodologies.
Solution:
char takes exactly 1 byte.x[0][0] to any offset x[i][j] equals (i * 3) + j independent bytes.x[0][2] sits at structural index 2 ($0 \times 3 + 2$). Its base address x[0][0] must logically be 0x20c - 2 = 0x20a.x[2][1]. Its raw offset from the base integer is (2 * 3) + 1 = 7 bytes.0x20a + 7 = 0x211.Problem: Hand-compile the following C for loop iteration into structural MIPS assembly. Assume $s0 = &arr[0] and $s1 = size = 10. The variables sum, pos, and neg represent $t0, $t1, and $t2 respectively (all natively initialized to $0$). $t3 operates iteratively as variable i.
for (i = 0; i < size; i++) {
sum += arr[i];
if (arr[i] > 0)
pos += arr[i];
if (arr[i] < 0)
neg += arr[i];
}
Solution:
# Initialize working variables iteratively
add $t0, $0, $0 # sum = 0
add $t1, $0, $0 # pos = 0
add $t2, $0, $0 # neg = 0
add $t3, $0, $0 # i = 0
FOR_LOOP:
slt $t4, $t3, $s1 # Evaluate: $t4 = 1 if i < size
beq $t4, $0, DONE # IF i >= size implies $t4 == 0, break loop sequentially
# Calculate physical address for array extraction: arr[i]
sll $t5, $t3, 2 # $t5 = i * 4 (shifting 2 bytes extracts Word offsets)
add $t5, $s0, $t5 # $t5 = base address origin + mathematical offset
lw $t6, 0($t5) # Register $t6 structurally now holds arr[i]
add $t0, $t0, $t6 # Evaluate integer logic: sum += arr[i]
# if (arr[i] > 0)
slt $t7, $0, $t6 # $t7 = 1 if (0 < arr[i]) translating directly to (arr[i] > 0)
beq $t7, $0, CHECK_NEG
add $t1, $t1, $t6 # Implement logic: pos += arr[i]
CHECK_NEG:
# if (arr[i] < 0)
slt $t7, $t6, $0 # $t7 = 1 if (arr[i] < 0)
beq $t7, $0, NEXT_ITER
add $t2, $t2, $t6 # Implement logic: neg += arr[i]
NEXT_ITER:
addi $t3, $t3, 1 # Iterate counter: i++
j FOR_LOOP # Jump structurally to repeat evaluation block
DONE:
# Function successfully routed and finalized natively
Course Coverage: Weeks 01-05
Replacing abstract block diagrams from our older syllabus, we now enforce explicit SystemVerilog (IEEE 1800) descriptions. You must be able to design, simulate, and analyze hardware circuits programmatically.
tb_module.sv. You must know how to instantiate a Device Under Test (DUT), initialize vectors inside initial blocks, apply delays (#10), and trap asserts using $display or $monitor.always_comb block that drives logic based off a switch statement checking an operation code.Problem: Design a three-input minimal AND-OR (minimal sum form) circuit implementing the following truth table for $F(A, B, C)$:
| A | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 |
|---|---|---|---|---|---|---|---|---|
| B | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 1 |
| C | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 |
| F | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 1 |
Please provide the detailed design calculations, including the Karnaugh map simplification.
Solution:
Problem: Express $F(x,y,z) = \overline{(\overline{x}+y)} + \overline{x}y$ in complete sum-of-products form using variables $x$, $y$, and $z$.
Solution: