Six instructions run on a five-stage pipeline. Say which instruction is in which stage, cycle by cycle.
Hardware context: The five stages of ap_rv32_p5 cut down to arithmetic, lw and sw, with the register file and the ALU of the real core and no hazard logic. Reading a pipeline diagram and a pipeline trace of a processor
The program below starts at address 0. It runs on the five-stage pipeline of the lesson. The first instruction is in IF in cycle 1. No instruction reads a register that another one writes, so nothing waits. Addresses are in decimal here, so that you can enter them as they are.
This worksheet uses named constants. The first three entries show how to record your decisions.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
question | 8 | input of each check |
Full specification
| Address, in decimal | Instruction |
|---|---|
| 0 | addi x5, x0, 1 |
| 4 | addi x6, x0, 2 |
| 8 | addi x7, x0, 3 |
| 12 | addi x8, x0, 4 |
| 16 | addi x9, x0, 5 |
| 20 | addi x10, x0, 6 |
| 24 | ebreak |
Draw the pipeline diagram first: a row for each instruction, a column for each cycle. Then read the answers from it. Enter every value in decimal.
| Entry | Your decision |
|---|---|
| STAGES | How many stages does an instruction pass through? |
| FIRST_IN_WB | In which cycle is the instruction at address 0 in WB? |
| IN_EX_AT_5 | Give the address of the instruction that is in EX in cycle 5. |
| IN_IF_AT_5 | Give the address of the instruction that is in IF in cycle 5. |
| CYCLE_OF_12_IN_MEM | In which cycle is the instruction at address 12 in MEM? |
| CYCLE_OF_20_IN_ID | In which cycle is the instruction at address 20 in ID? |
| AT_WORK_IN_3 | How many instructions of the program are in the pipeline in cycle 3? |
| AT_WORK_IN_6 | How many instructions of the program are in the pipeline in cycle 6? |
| AT_WORK_IN_9 | How many instructions of the program are in the pipeline in cycle 9? |
| CYCLE_X7_WRITTEN | The instruction at address 8 writes x7. In which cycle is it in WB? |
| SINGLE_CYCLE | How many cycles do the six instructions take on the single-cycle core, after its first fetch? |
| LAST_WB_FOR_K | The program has K instructions before the ebreak. Give the cycle in which the last of them is in WB, as an expression in K. |
Examples
Example 1
STAGES- Input
How many stages does an instruction pass through?
- Output
matches = 1
IF, ID, EX, MEM and WB.
Example 2
FIRST IN WB- Input
In which cycle is the instruction at address 0 in WB?
- Output
matches = 1
It is in IF in cycle 1. WB is four stages later.
Example 3
IN EX AT 5- Input
Give the address of the instruction that is in EX in cycle 5.
- Output
matches = 1
The instruction in WB is at 0. EX is two stages behind it: two instructions, 8 bytes.
Constraints and Contract
- Keep the parameter and named constants. Use the numeric codes and units on this page.
- For LAST_WB_FOR_K, enter a constant expression using K. Only this entry changes with the parameter. The supported integer range is 1 through 40, inclusive.
Hints
Hint 1
Each row of the diagram is the row above it, moved one cycle to the right.
Hint 2
To follow an instruction, read its row. To see one cycle, read its column.
Hint 3
The instruction number n is in IF in cycle n. Add 1 for each stage after IF.
What the grader checks: Each check compares the full eight-bit answer. Parameter trials change one condition and keep the other decisions fixed.
12 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 3 problems on this path