Electronic – “Increase” of a register in VHDL and hardware synthesis

digital-logichdlregistersignalvhdl

Suppose you have already defined a register (for instance called "reg") in VHDL, for instance as a vectors of 4 bit.

Now consider the operation: reg <= reg + 0001; it is like reg ++ in C.

My questions are:

1) how can reg store the result of the sum between reg itself and another number? The result is expressed by 4 sum bits and 1 carry bit, so there are 5 bits…

2) how will the synthesis be? An adder which takes 0001 and reg as input will give 5 output wires… How will they be connected to reg (which has only 4 input wires)?

Best Answer

The carry-out is ignored in such expressions. If you care about it, you need to account for it explicitly. For example, you could write something like this:

-- perform the addition, making room for the carry-out
signal sum : std_logic_vector (4 downto 0);
sum <= ("0" & reg) + "00001";

-- update the register and capture the carry-out at the same time
process ...
    reg <= sum (3 downto 0);
    carry <= sum (4);
end