Repair an 8-bit ripple-carry adder whose carries never reach the next bit.
Hardware context: One bit of a gate-array adder and an 8-bit ripple-carry adder built from tested full adders. Repair the carry chain of an 8-bit ripple-carry adder.
A student built an 8-bit adder from eight copies of a tested full adder. The code compiles, but every sum comes out unknown, even 1 + 2.
This is a Fix problem. The full adder is read-only and correct. The bug is in how add8 connects the eight copies. Keep the eight full adders: the check counts them.
The check applies eight additions, one per nanosecond, and records co and s after each.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
script | 136 | input of each check |
Full specification
module add8 (
input logic [7:0] a, b,
input logic ci,
output logic [7:0] s,
output logic co
);
// eight full_adder copies
endmodule
// full_adder.sv: the full adder (read-only). Every copy adds 1 to tb.n_fa and reports its outputs.
module full_adder (input logic a, b, ci, output logic s, co);
int idx;
assign {co, s} = a + b + ci;
initial idx = tb.n_fa++;
always @(s or co) if (idx < 16) begin tb.fa_s[idx] = s; tb.fa_co[idx] = co; end
endmodule
| Rule | Detail |
|---|---|
| Function | {co, s} = a + b + ci, a 9-bit result. |
| Structure | Exactly eight full_adder copies, one per bit, chained through their carries. |
The result fields are co_stepK and s_stepK for the steps 0 to 7, adder_count_wrong and outputs_not_from_the_adders.
Examples
Example 1
Small Sums with No Carry- Input
01 + 02 + 0; 03 + 04 + 0; 10 + 20 + 0; 0f + 30 + 0; 00 + 00 + 0; 40 + 3f + 0; 05 + 0a + 0; 21 + 12 + 0
- Output
co_step0 = no, s_step0 = 0x3, co_step1 = no, s_step1 = 0x7, co_step2 = no, s_step2 = 0x30, co_step3 = no, s_step3 = 0x3f, co_step4 = no, s_step4 = 0x0, co_step5 = no, s_step5 = 0x7f, co_step6 = no, s_step6 = 0xf, co_step7 = no, s_step7 = 0x33, adder_count_wrong = no, outputs_not_from_the_adders = no
No bit makes a carry here, yet the starter shows x: its carry chain is broken at both ends.
Example 2
A Carry from Bit 0 to Bit 1- Input
01 + 01 + 0; 03 + 01 + 0; 01 + 03 + 0; 02 + 02 + 0; 07 + 01 + 0; 01 + 00 + 1; 03 + 00 + 1; 0f + 01 + 0
- Output
co_step0 = no, s_step0 = 0x2, co_step1 = no, s_step1 = 0x4, co_step2 = no, s_step2 = 0x4, co_step3 = no, s_step3 = 0x4, co_step4 = no, s_step4 = 0x8, co_step5 = no, s_step5 = 0x2, co_step6 = no, s_step6 = 0x4, co_step7 = no, s_step7 = 0x10, adder_count_wrong = no, outputs_not_from_the_adders = no
1 + 1 = 2: the carry out of bit 0 must reach bit 1. Follow c[1] in the starter and see which way it goes.
Example 3
Carries Across the Whole Byte- Input
ff + 01 + 0; ff + 00 + 1; 80 + 80 + 0; ff + ff + 1; 7f + 01 + 0; fe + 01 + 1; c0 + 40 + 0; ff + ff + 0
- Output
co_step0 = yes, s_step0 = 0x0, co_step1 = yes, s_step1 = 0x0, co_step2 = yes, s_step2 = 0x0, co_step3 = yes, s_step3 = 0xff, co_step4 = no, s_step4 = 0x80, co_step5 = yes, s_step5 = 0x0, co_step6 = yes, s_step6 = 0x0, co_step7 = yes, s_step7 = 0xfe, adder_count_wrong = no, outputs_not_from_the_adders = no
ff + 01 = 100: the carry crosses all eight bits and sets co.
Constraints and Contract
- Inputs are known 0/1 values. Each addition is held for one nanosecond and the outputs are sampled at its end.
- Keep the module name and the ports.
Hints
Hint 1
Trace one carry net, c[1]. Which stage drives it, and which stage reads it? A carry must flow from bit 0 toward bit 7.
Hint 2
c[i] is the carry into bit i. So stage i must read c[i] and drive the carry into the bit above it.
Hint 3
After the fix, check the two ends: c[0] comes from ci, and co is the carry out of bit 7.
What the grader checks: Five directed and eight seeded cases of eight additions each are compared with a + b + ci computed in JavaScript. The full adder copies are counted, and their own outputs must account for co and s.
13 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 2 steps and the final capstone