G4.3.3 A Decoder That Doubles as a Demultiplexer

EasyImplementIcarus Verilog + Yosys · serverReview the topic

Write a 3-to-8 decoder with an active-low enable and active-low outputs that also works as a demultiplexer.

Hardware context: Relay boards, a repair board and a controller with active-low device lines, all driven by 3-to-8 decoders. Write a decoder with an active-low enable that also serves as a demultiplexer.

A controller has eight device lines that idle high. One part must serve two jobs. At start-up it selects one device by pulling its line low. Later it carries a serial data stream to one device, with every other line held high.

This is an Implement problem. Write dec3to8n. When en_n = 0, output a is 0 and the other seven outputs are 1. When en_n = 1, all eight outputs are 1. As a demultiplexer the data stream drives en_n, so the selected line copies the data and the others stay high.

The check applies eight (en_n, a) inputs, one per nanosecond, and records y_n after each. The check also synthesizes the module on the site's flow and rejects any latch.

Signals in the Timeline

SignalWidthRole
script32input of each check
Full specification
The module (keep the name and the ports)
module dec3to8n (
  input  logic [2:0] a,          // the address, or the select of the demultiplexer
  input  logic       en_n,       // active-low enable; as a demultiplexer, the data line
  output logic [7:0] y_n         // active-low outputs
);
  // your design
endmodule
en_nay_n
1any11111111
0kbit k is 0, every other bit is 1

The result fields are named y_n_step0 to y_n_step7, shown in binary from bit 7 down to bit 0.

Examples

Example 1

As a Decoder: Addresses 0 to 7
Input
en_n=0 a=0; en_n=0 a=1; en_n=0 a=2; en_n=0 a=3; en_n=0 a=4; en_n=0 a=5; en_n=0 a=6; en_n=0 a=7
Output
y_n_step0 = 'b11111110, y_n_step1 = 'b11111101, y_n_step2 = 'b11111011, y_n_step3 = 'b11110111, y_n_step4 = 'b11101111, y_n_step5 = 'b11011111, y_n_step6 = 'b10111111, y_n_step7 = 'b01111111

Enabled, address k pulls bit k low: 11111110 for 0, up to 01111111 for 7.

Example 2

Disabled at Every Address
Input
en_n=1 a=0; en_n=1 a=1; en_n=1 a=2; en_n=1 a=3; en_n=1 a=4; en_n=1 a=5; en_n=1 a=6; en_n=1 a=7
Output
y_n_step0 = 'b11111111, y_n_step1 = 'b11111111, y_n_step2 = 'b11111111, y_n_step3 = 'b11111111, y_n_step4 = 'b11111111, y_n_step5 = 'b11111111, y_n_step6 = 'b11111111, y_n_step7 = 'b11111111

With en_n = 1, no line is selected, so all eight stay high.

Example 3

As a Demultiplexer
Input
en_n=1 a=2; en_n=0 a=2; en_n=0 a=2; en_n=1 a=2; en_n=1 a=5; en_n=0 a=5; en_n=0 a=5; en_n=1 a=5
Output
y_n_step0 = 'b11111111, y_n_step1 = 'b11111011, y_n_step2 = 'b11111011, y_n_step3 = 'b11111111, y_n_step4 = 'b11111111, y_n_step5 = 'b11011111, y_n_step6 = 'b11011111, y_n_step7 = 'b11111111

The data 1, 0, 0, 1 drives en_n with a = 2. Line 2 shows 1, 0, 0, 1, a copy of the data. Then the same stream goes to line 5.

Constraints and Contract

  • Inputs are known 0/1 values. Each input is held for one nanosecond and y_n is sampled at its end.
  • Keep the module name and the ports. The design is combinational: no clock and no stored value.

Hints

Hint 1

Start every output at 1, then pull one output to 0 only when the decoder is enabled.

Hint 2

en_n is active-low: the decoder is on when en_n is 0. Check the polarity of every test you write on it.

Hint 3

With data on en_n, a data bit of 0 enables the decoder and pulls the selected line low. A data bit of 1 leaves every line high. So the selected line copies the data.

What the grader checks: Six directed and eight seeded cases of eight steps each cover every address, enabled and disabled, and two data streams. y_n is compared with a model written in JavaScript after every step. The synthesis check rejects a latch.

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.

14 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 4 steps and the final capstone

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

As a Decoder: Addresses 0 to 7

Input
en_n=0 a=0; en_n=0 a=1; en_n=0 a=2; en_n=0 a=3; en_n=0 a=4; en_n=0 a=5; en_n=0 a=6; en_n=0 a=7
Expected output
y_n_step0 = 'b11111110, y_n_step1 = 'b11111101, y_n_step2 = 'b11111011, y_n_step3 = 'b11110111, y_n_step4 = 'b11101111, y_n_step5 = 'b11011111, y_n_step6 = 'b10111111, y_n_step7 = 'b01111111

Enabled, address k pulls bit k low: 11111110 for 0, up to 01111111 for 7.

Run samples executes all 3 public checks. Check all tests runs 14 checks on the server.

Icarus Verilog + Yosys · server