Adder

Start with a full adder and follow its carry into the next bit. With four-bit inputs, 15 plus 1 yields 16 with the fifth bit kept and 0 with a four-bit result. Use the example to set the output width and distinguish unsigned carry from signed overflow.

The collector adds the four-bit words F and 1. As unsigned values, they add to sixteen. A four-bit output shows only zero. Keeping the fifth bit lets the receiver see whether the addition carried out.

Keep the carry and check the signed range separately

Zero-extend A and B to five bits, then add the incoming carry cin. F+1 gives 1_0000. The top bit goes to carry and the four low bits go to sum. The carry input can come from a previous arithmetic stage. 7+0+1 and 7+1+0 then give the same result.

At each bit, add the two input bits and the carry from the previous bit. A full adder takes those three bits and produces a sum bit and a carry. In F+1, the low bit adds 1+1+0, producing sum zero and carry one. Each higher bit adds 1+0+1 and passes the carry up. This explains the arithmetic. Synthesis can choose a different carry structure.

Read F as four-bit two’s-complement −1 and F+1 has signed sum zero, inside the range −8 to 7. Its overflow is zero. For 7+1, the mathematical signed result is eight and the low pattern 1000 would read as −8. This time overflow=1. The unsigned result is eight, so carry=0. The RTL detects signed overflow when the operands have the same sign and the result changes sign.

The low four bits and two different flags. F + 1 gives 10. Four-bit sum = 0 and unsigned carry = 1.
F + 1 gives 10. Four-bit sum = 0 and unsigned carry = 1.

Synthesizable SystemVerilog

module adder4 (
    input  logic [3:0] a,
    input  logic [3:0] b,
    input  logic cin,
    output logic [3:0] sum,
    output logic carry,
    output logic overflow
);
    logic [4:0] wide_sum;
    assign wide_sum = {1'b0, a} + {1'b0, b} + {4'b0, cin};
    assign {carry, sum} = wide_sum;
    assign overflow = (a[3] == b[3]) && (sum[3] != a[3]);
endmodule

Check the results against the waveform

Data values are hexadecimal. Control signals and flags are shown separately.

Change atabcinsumcarryoverflow
0 nsF10010
10 ns710801
20 ns701801
30 ns880011
40 ns430700
F + 1 sets carry. 7 + 1 sets signed overflow.
The plot uses the VCD generated by the Icarus run.

If the interface uses an unsigned modulo result, sum=0 is the expected answer. Pass {carry,sum} together to preserve the full unsigned sum.

Download the runnable SystemVerilog lab. Icarus checks the 5 rows above and 512 binary input combinations. It reads each directed result 1 ns after changing the inputs. The wait sets an observation time in the testbench. The waveform is functional evidence. Physical delay needs a timing model.

Interactive lab

Start with carry for F+1, then inspect overflow for 7+1. Change cin to include carry from an earlier stage.

Low sum (hex)
Unsigned carry
Signed overflow
Show the last eight observations

    Teaching film

    Read the transcript

    Run the RTL yourself

    Extract the lab and follow the commands in its README. Compare the simulated outputs and waveform with your predictions from the interactive lab.

    Download Adder RTL (.zip)

    Check your understanding

    1. What are sum and carry for four-bit unsigned F + 1 with cin=0?
    2. What are carry and signed overflow for 7 + 1?
    3. With A=7, B=0, and cin=1, what are the low four bits in hex?
    4. Which addition sets both carry and signed overflow?
    5. What should the receiver read for the full unsigned sum?