Verilog: n-Bit Adder

This is code is for an simple asynchronous wrapping n-bit adder. By changing the value of n you can make it a 2, 4, … bit adder where n = <number of bits> – 1. f is the output register that will have the current value of the counter, cOut is the carry output. a & b are the number inputs and cIn is the carry input. Both the number outputs and inputs are set by the value of n so you can add two n-bit numbers and a carry bit then get an n-bit number plus carry bit out.


7 thoughts on “Verilog: n-Bit Adder

    • You can, you would have to use two n-bit adders to add two sets of two numbers. Then use an n+1 bit bit adder to add those two numbers. Think of it as (a+b)+(c+d) were (a+b) and (c+d) use two n-bit adders then you use an n+1 bit adder to add the results of the first two adder s.

  1. Isn’t this a 3 input adder, not a 3bit adder if you have a and b sized as n-bit arrays? if you change n to 3, then you are adding 2 inputs of 3 bits each which will output a maximum value of ((2^2 * 1 + 2^1 * 1 + 2^0 * 1) + (2^2 * 1 + 2^1 * 1 + 2^0 * 1)) = 1110 so you’d get 110 in the F reg and a 1 to the Cout reg.

    a 3 bit adder would be if a is high, b is high, and cin is high, each carrying in only one bit right? this program would program three flip flops that when all hi add up to 3 represented by 11 2-bits that can be stored in an output containing two flip flops right?

    • Correct, In essence it is a three input adder with two n-bit inputs and a 1-bit cary input. This is called a full adder, there is also a half adder which does not have the carry input.

Leave a Reply

Your email address will not be published. Required fields are marked *