Build a full adder from one 3-to-8 decoder with active-low outputs and two gates.
Hardware context: Relay boards, a repair board and a controller with active-low device lines, all driven by 3-to-8 decoders. Build a full adder from one active-low decoder and two gates.
A repair board must add three bits, and the only spare parts are a 3-to-8 decoder and a few gates. The decoder has active-low outputs: the selected output goes to 0. It also has three enables, and it works only when g1 = 1 and both g2a_n and g2b_n are 0.
This is an Implement problem. Write fa_dec as a netlist of cells from the read-only library. Use the decoder once and at most two other cells. a goes to the decoder's most significant input, then b, then ci.
The check applies the eight rows of a, b and ci, one every 4 ns. It records the carry and the sum after each row, and counts your cells.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
script | 24 | input of each check |
Full specification
module fa_dec (
input logic a, b, ci, // a is the most significant decoder input
output wire s, co
);
// your netlist
endmodule
// deccells.sv: the cell library (read-only). Every cell takes 1 ns. Ports: outputs first.
// The cells count themselves: tb.n_dec for the decoder, tb.n_gate for every other cell.
// DEC38: a 3-to-8 decoder with active-low outputs. It is enabled when g1 = 1, g2a_n = 0 and g2b_n = 0;
// then y_n[k] = 0 for k = {a2, a1, a0} and every other output is 1. Disabled, all outputs are 1.
module DEC38 (output wire [7:0] y_n, input wire a2, a1, a0, g1, g2a_n, g2b_n);
assign #1 y_n = (g1 && !g2a_n && !g2b_n) ? ~(8'b1 << {a2, a1, a0}) : 8'hFF;
initial tb.n_dec++;
endmodule
module INV (output wire y, input wire a); not #1 (y, a); initial tb.n_gate++; endmodule
module NAND2 (output wire y, input wire a, b); nand #1 (y, a, b); initial tb.n_gate++; endmodule
module NAND3 (output wire y, input wire a, b, c); nand #1 (y, a, b, c); initial tb.n_gate++; endmodule
module NAND4 (output wire y, input wire a, b, c, d); nand #1 (y, a, b, c, d); initial tb.n_gate++; endmodule
module OR4 (output wire y, input wire a, b, c, d); or #1 (y, a, b, c, d); initial tb.n_gate++; endmodule
module AND4 (output wire y, input wire a, b, c, d); and #1 (y, a, b, c, d); initial tb.n_gate++; endmodule
| Rule | Detail |
|---|---|
| Function | {co, s} = a + b + ci for every row. |
| Cost | One decoder and at most two other cells. |
| Decoder | Inputs a, b, ci with a on a2. Tie the enables with 1'b1 and 1'b0 constants. |
| Nets | Declare the decoder outputs as wire [7:0]; pick single bits with a constant index. |
The result shows co and s after each of the eight rows, and whether the cell count is over the budget.
Examples
Example 1
Rows 0 to 7- Input
000, 001, 010, 011, 100, 101, 110, 111 (a b ci)
- Output
co_step0 = no, s_step0 = no, co_step1 = no, s_step1 = yes, co_step2 = no, s_step2 = yes, co_step3 = yes, s_step3 = no, co_step4 = no, s_step4 = yes, co_step5 = yes, s_step5 = no, co_step6 = yes, s_step6 = no, co_step7 = yes, s_step7 = yes, over_budget = no
The rows in order. The sum is 1 when one or three inputs are 1; the carry is 1 when two or three are.
Example 2
Rows 7 Down to 0- Input
111, 110, 101, 100, 011, 010, 001, 000 (a b ci)
- Output
co_step0 = yes, s_step0 = yes, co_step1 = yes, s_step1 = no, co_step2 = yes, s_step2 = no, co_step3 = no, s_step3 = yes, co_step4 = yes, s_step4 = no, co_step5 = no, s_step5 = yes, co_step6 = no, s_step6 = yes, co_step7 = no, s_step7 = no, over_budget = no
The same rows backwards. Row 7, 1 + 1 + 1, gives carry 1 and sum 1.
Example 3
One Input at a Time- Input
000, 100, 000, 010, 000, 001, 000, 111 (a b ci)
- Output
co_step0 = no, s_step0 = no, co_step1 = no, s_step1 = yes, co_step2 = no, s_step2 = no, co_step3 = no, s_step3 = yes, co_step4 = no, s_step4 = no, co_step5 = no, s_step5 = yes, co_step6 = no, s_step6 = no, co_step7 = yes, s_step7 = yes, over_budget = no
A single 1 on any input gives sum 1 and carry 0. A full adder treats its three inputs alike.
Constraints and Contract
- Inputs are known 0/1 values. Each row is held for 4 ns before the outputs are read.
- Keep the module name and the ports.
Hints
Hint 1
Write the truth table of a full adder. List the rows where s is 1, and the rows where co is 1. Each list is a sum of minterms.
Hint 2
Each decoder output is one minterm, but active-low: it is 0 when its row is the input. You need a gate that gives 1 when any of its inputs is 0.
Hint 3
Check the enables: the decoder selects nothing unless g1 is 1 and both other enables are 0.
What the grader checks: Five directed and six seeded cases apply eight rows each; every row of the table appears several times. co and s are compared with a + b + ci computed in JavaScript. The source may hold only cell instances, one decoder and at most two other cells.
11 checks on Icarus · browser samples / server checks. 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