4-bit Up Counter with Asynchronous Reset

Problem Description
Design a 4-bit up counter that increments count by 1 on every rising edge of clk. The counter counts from 0 to 15 and wraps back to 0 automatically on overflow. When rst is asserted high, count resets to 0 immediately — independent of the clock edge. The reset is asynchronous and takes priority over counting.
Interface Definition
Port | Direction | Width | Description |
|---|---|---|---|
clk | input | 1-bit | Positive-edge triggered clock |
rst | input | 1-bit | Active-high asynchronous reset — resets count to 0 immediately |
count | output | 4-bit | Registered counter output, 0 to 15, wraps on overflow |
All Scenarios
Scenario | count value | What happens |
|---|---|---|
Normal count | 0→1→2...15 | Increments each posedge ✓ |
Overflow | 15 → 0 | Wraps automatically ✓ |
Async reset mid cycle | any → 0 | Resets immediately ✓ |
Reset at overflow | 15 → 0 | Reset wins, drops instantly ✓ |
rst deasserted | 0 → 1 | Resumes counting ✓ |
rst held high | stays 0 | Count frozen at 0 ✓ |
Worked Example — Cycle Trace
cycle │ clk event │ rst │ count │ Decision
──────┼────────────┼─────┼───────┼──────────────────────────────────
1 │ posedge │ 0 │ 0 │ rst=0, increment → count=1
2 │ posedge │ 0 │ 1 │ rst=0, increment → count=2
3 │ posedge │ 0 │ 2 │ rst=0, increment → count=3
...
16 │ posedge │ 0 │ 15 │ rst=0, increment → wraps to 0 ✓
17 │ mid-cycle │ 1 │ 3 │ rst HIGH → count=0 IMMEDIATELY ✓
18 │ posedge │ 0 │ 0 │ rst=0, increment → count=1
Verilog
Code Editor Access
Log in to write, run and submit your solution to this interview question. It's free.
