The arithmetic functions

The basic arithmetic operations, addition (+), subtraction (-) and multiplication (*) are defined on the unsigned and signed types. The + and - operators can also be used to indicate a positive or negative value.

Each of the operators can take unsigned, signed and integer values as arguments. They can return unsigned, signed or std_logic_vector values as needed.

Note that this library doesn't allow you to do arithmetic on std_logic_vector values. That's because it's impossible for it to determine whether a particular std_logic_vector is representing a signed or unsigned value. To do this, you need to use either the std_logic_unsigned or std_logic_signed libraries.

Examples

signal u1, u2 : unsigned (3 downto 0);
signal s1 : signed (3 downto 0);
signal s2 : signed (4 downto 0);
signal v1 : std_logic_vector (3 downto 0);
signal v2 : std_logic_vector (4 downto 0);
signal i1, i2 : integer;
...
u1 <= "1001";    -- = 9
s1 <= "1001";    -- = -7
i1 <= 16;
wait for 10 ns;
s2 <= u1 + s1;   -- = 2
v2 <= u1 + s1;   -- = "0010"
u2 <= i1 - u1;   -- = 7
s1 <= -s1;       -- = 7