Hello I would like to ask, how could I add two vectors in VHDL, which one of them is 7 downto 0 and the other one is 8 downto 0. I tried something like this, but it does not work. Thank you in advance.
IS_CARRY <= '0' & (IN1 + IN2)
You need to extend the shorter vector to 9 bits and then do the addition.
Declarations:
signal in1 : UNSIGNED(7 downto 0);
signal in2 : UNSIGNED(8 downto 0);
signal res : UNSIGNED(8 downto 0);
Example:
res <= ('0' & in1) + in2;
It's not recommended to use STD_LOGIC_ARITH and STD_LOGIC_UNSIGNED. Use NUMERIC_STD instead. Doing arithmetic on STD_LOGIC_VECTORs is no good style. Use the types SIGNED and UNSIGNED for this purpose.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With