Step a program through a reset and one timer interrupt, and find where the PC goes and comes back.
Hardware context: Teaching processor with a reset and one timer interrupt. Reading an interrupt entry and return in a trace
The teaching processor of lesson S0.8 runs the two programs below. Reset is held for the first two clock edges, e1 and e2, and one instruction runs at every edge after that. The reset address is 0 and the handler starts at address 8. The timer fires at edge e7. The switches at address 15 show 6.
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
| Box (address) | Instruction | Part of |
|---|---|---|
| 0 | LOAD r1, 12 | main program |
| 1 | LOAD r2, 13 | main program |
| 2 | ADD r0, r1 | main program |
| 3 | SUB r1, r2 | main program |
| 4 | JUMPNZ r1, 2 | main program |
| 5 | STORE r0, 11 | main program |
| 6 | HALT | main program |
| 8 | LOAD r3, 15 | handler |
| 9 | STORE r3, 14 | handler |
| 10 | RETI | handler |
| 12 | the number 2 | data |
| 13 | the number 1 | data |
An interrupt is taken at the edge where the timer fires, before the instruction of that edge is fetched. The first instruction of the handler runs at that same edge.
| Entry | Your decision |
|---|---|
| FIRST_EDGE | Number of the edge at which the first instruction runs. |
| FIRST_PC | Address of the first fetch after reset. |
| PC_AT_E6 | Address of the instruction that runs at edge 6. |
| SAVED_PC | Address that goes into the saved PC when the interrupt is taken. |
| FORCED_PC | Address forced into the PC at edge 7. |
| LAMPS | Value that the handler writes to the lamps. |
| RETI_EDGE | Number of the edge at which RETI runs. |
| RESUME_PC | Address of the instruction that runs at edge 10. |
| LOST_EDGES | Number of edges the main program lost to the interrupt. |
| SUM | Value in box 11 when the processor halts. |
| HALT_EDGE | Number of the edge at which HALT runs. |
| LATE_HALT_EDGE | At which edge would the HALT run if the handler had EXTRA more instructions before its RETI? |
Examples
Example 1
FIRST EDGE- Input
Number of the edge at which the first instruction runs.
- Output
matches = 1
Edges 1 and 2 are spent in reset. The instruction in box 0 runs at edge 3.
Example 2
FIRST PC- Input
Address of the first fetch after reset.
- Output
matches = 1
A reset forces the PC to the reset address, 0.
Example 3
PC AT E6- Input
Address of the instruction that runs at edge 6.
- Output
matches = 1
Edges 3, 4, 5 and 6 run boxes 0, 1, 2 and 3.
Constraints and Contract
- Keep the parameter and named constants. Use the numeric codes and units on this page.
- For LATE_HALT_EDGE, enter a constant expression using EXTRA. Only this entry changes with the parameter. The supported integer range is 0 through 15, inclusive.
Hints
Hint 1
Write one row for each edge from 3 onwards, with the PC and the instruction.
Hint 2
At edge 7, note the PC as the saved PC, and carry on from address 8.
Hint 3
After RETI, carry on from the saved PC as if nothing had happened.
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 1 problem on this path