Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Intel Community
- FPGAs and Programmable Solutions
- Programmable Devices
- Adding Hex number- carry problem

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Altera_Forum

Honored Contributor I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-08-2011
08:07 PM

718 Views

Adding Hex number- carry problem

Hi,

I want to add two hex numbers inside the process. Attached herewith is my code: " signal TX_checkSum: std_logic_vector (7 downto 0); begin process... 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?
1 Reply

Altera_Forum

Honored Contributor I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-09-2011
01:37 AM

17 Views

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.For more complete information about compiler optimizations, see our Optimization Notice.