jinbow
Newbie level 3
Hi all,
I'm trying to do a 8-bit full adder example in Pedroni's VHDL book.
Below is his code which works when simulated:
During simulation, whenever cin is '1', the c[0] is 'X', and causes sum[0] to be 'X'.
Below is the simulation diagram.
I know I can use a generate statement to do this outside of a process, but just wanted to know why this happens.
Please advise.
Thanks,
ALbert
I'm trying to do a 8-bit full adder example in Pedroni's VHDL book.
Below is his code which works when simulated:
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 ================================================= library IEEE; use IEEE.std_logic_1164.all; entity temp is generic( bits: positive := 8); port ( cin : in std_logic; a : in std_logic_vector(bits-1 downto 0); b : in std_logic_vector(bits-1 downto 0); sum : out std_logic_vector(bits-1 downto 0); cout : out std_logic); end entity; architecture arch of temp is begin process(a, b, cin) variable c: std_logic_vector(bits downto 0) := (others => '0'); begin c(0) := cin; for i in 0 to bits-1 loop sum(i) <= a(i) xor b(i) xor c(i); c(i+1) := (a(i) and b(i)) or (a(i) and c(i)) or (b(i) and c(i)); end loop; cout <= c(bits); end process; end architecture; ================================================= I am trying not to use variable, but use signal as the type for c as shown below: ================================================= architecture arch of temp is signal c: std_logic_vector(bits downto 0) := (others => '0'); begin c(0) <= cin; process(a, b, c(0)) begin for i in 0 to bits-1 loop sum(i) <= a(i) xor b(i) xor c(i); c(i+1) <= (a(i) and b(i)) or (a(i) and c(i)) or (b(i) and c(i)); end loop; end process; cout <= c(bits); end architecture; =================================================
Below is the simulation diagram.
I know I can use a generate statement to do this outside of a process, but just wanted to know why this happens.
Please advise.
Thanks,
ALbert
Last edited by a moderator: