Build a 16-bit control register with an asynchronous active-low reset, a synchronous clear and two byte enables.
Hardware context: A peripheral's 16-bit control register written a byte at a time, and a three-stage audio echo pipeline. Build a register with an asynchronous reset, a synchronous clear and byte enables.
A peripheral has a 16-bit control register. Software writes it one byte at a time, so each byte has its own enable. A power-on reset must set it to 00ff at once, even with no clock. Software can also clear it, but only at a clock edge.
This is an Implement problem. Complete ctrl_reg. The check sets the inputs while the clock is low and looks at q. Then it makes one rising edge and reads q again.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
script | 84 | input of each check |
Full specification
module ctrl_reg (
input logic clk,
input logic rst_n, // asynchronous reset, active low: q becomes 16'h00ff at once
input logic clr, // synchronous clear: q becomes 0 at the next rising edge
input logic [1:0] be, // byte enables: be[1] loads d[15:8], be[0] loads d[7:0]
input logic [15:0] d,
output logic [15:0] q
);
...
endmodule
| Priority | Condition | q becomes |
|---|---|---|
| 1 | rst_n = 0, at any time | 16'h00ff at once, and it stays there while rst_n is 0 |
| 2 | clr = 1 at a rising edge | 16'h0000 |
| 3 | be[1] = 1 at a rising edge | q[15:8] takes d[15:8] |
| 3 | be[0] = 1 at a rising edge | q[7:0] takes d[7:0] |
| otherwise | q keeps its value |
Each case starts with a reset pulse and runs four steps. The result shows q after each edge, and whether q moved before each edge.
Examples
Example 1
Byte Loads from the Reset Value- Input
clr0 be01 d=1234; clr0 be10 d=abcd; clr0 be00 d=ffff; clr0 be11 d=5aa5
- Output
q_after_edge1 = 0x34, q_after_edge2 = 0xab34, q_after_edge3 = 0xab34, q_after_edge4 = 0x5aa5, q_moved_before_edge1 = no, q_moved_before_edge2 = no, q_moved_before_edge3 = no, q_moved_before_edge4 = no
From 00ff, be = 01 loads only the low byte: 0034. Then be = 10 loads only the high byte: ab34. be = 00 holds, and be = 11 loads both.
Example 2
A Clear Against the Enables- Input
clr0 be11 d=beef; clr1 be11 d=7777; clr0 be10 d=3c00; clr1 be00 d=0000
- Output
q_after_edge1 = 0xbeef, q_after_edge2 = 0x0, q_after_edge3 = 0x3c00, q_after_edge4 = 0x0, q_moved_before_edge1 = no, q_moved_before_edge2 = no, q_moved_before_edge3 = no, q_moved_before_edge4 = no
When clr and both enables are 1 at the same edge, the clear wins and q becomes 0000.
Example 3
A Reset Pulse Between Edges- Input
clr0 be11 d=4242; reset pulse, clr0 be00 d=9999; clr0 be01 d=0066; reset pulse, clr1 be11 d=1111
- Output
q_after_edge1 = 0x4242, q_after_edge2 = 0xff, q_after_edge3 = 0x66, q_after_edge4 = 0x0, q_moved_before_edge1 = no, q_moved_before_edge2 = yes, q_moved_before_edge3 = no, q_moved_before_edge4 = yes
In step 2, rst_n pulses low with no clock edge. q must jump to 00ff at once, so the "moved" field is true. Then be = 00 holds it.
Constraints and Contract
- All inputs are known 0/1 values. rst_n changes only while the clock is low.
- Keep the module name and the ports. The design must synthesize with no latches.
Hints
Hint 1
An asynchronous reset must be in the sensitivity list. It is active low here, so its event is negedge rst_n.
Hint 2
The order of the if statements sets the priority: reset first, then the clear, then the loads.
Hint 3
Each byte enable controls its own half of q. Two separate if statements let both bytes load in one edge.
What the grader checks: Four directed and twelve seeded scripts of four steps, with reset pulses between edges and resets held through an edge. q is compared with a JavaScript model after every edge, and the check records whether q moved before each edge. Synthesis must report no latches.
The submitted design must synthesize with 0 latches and no combinational loop. Counts come from the pinned open-source synthesis flow. They are proxies for logic size and depth, not physical area or timing.
16 checks on Icarus Verilog + Yosys · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 steps and the final capstone