Showing results for 
Search instead for 
Did you mean: 
Honored Contributor I

Adding Hex number- carry problem


I want to add two hex numbers inside the process. 

Attached herewith is my code: 

signal TX_checkSum: std_logic_vector (7 downto 0); 



case loop_back is 

when stage_one=> 


TX_checkSum<= (x"FF" +x"11"); 


end case; 

end process; 

The answer is not good (x"10" instead x"110"). The problems is with the bit that will be added due to the adding operation: 

If I'll write: "TX_checkSum<= (x"FF" +x"11");"- I will cancel the carry. 

If I'll write: "signal TX_checkSum: std_logic_vector (8 downto 0);" -I will get an error (expression "('0','0','0','1','0','0','0','0')" has 8 elements ; expected 9 elements) 

If I'll add: " TX_checkSum<=('0' & (x"FF" +x"11");"- I will cancel the carry again (x"010" instead x"110")... 

What should I do?
0 Kudos
1 Reply
Honored Contributor I

For a start, why add two constants in code (hardware) when you can just insert a precomputed result. This is a basic resource usage principle. 


However, if you want to add two values then sign extend the inputs by one bit and add up to a result one bit wider than input. 


Result <= A(7) & A + B(7) & B; -- assuming 8 bit inputs 


also be warned that if you add up in every case statement then you are asking for an adder instant per case. The compiler is not clever enough to use fewer adders with inputs switching.
0 Kudos