#### killersbeez

##### Newbie level 3

hello, i have question hot to program adder with 4 inputs in VHDL!

i have made this VHDL code is it correct?!

Library ieee;

Use ieee.std_logic_1164.all;

ENTITY adder IS

generic (dummy : time := 0 ns);

PORT( A,B,C,D : IN std_logic;

sum: OUT std_logic);

END ENTITY;

ARCHITECTURE functional OF adder IS

BEGIN

PROCESS(A,B,C,D)

BEGIN

if ( A = '0' and B = '0' and C = '0' and D = '0' ) then

sum<= '0'

else

if ( A = '0' and B = '0' and C = '0' and D = '1' ) then

sum<= '1'

else

if ( A = '0' and B = '0' and C = '1' and D = '0' ) then

sum<= '1'

else

if ( A = '0' and B = '0' and C = '1' and D = '1' ) then

sum<= '0'

else

if ( A = '0' and B = '1' and C = '0' and D = '0' ) then

sum<= '1'

else

if ( A = '0' and B = '1' and C = '0' and D = '1' ) then

sum<= '0'

else

if ( A = '0' and B = '1' and C = '1' and D = '0' ) then

sum<= '0'

else

if ( A = '0' and B = '1' and C = '1' and D = '1' ) then

sum<= '1'

else

if ( A = '1' and B = '0' and C = '0' and D = '0' ) then

sum<= '1'

else

if ( A = '1' and B = '0' and C = '0' and D = '1' ) then

sum<= '0'

else

if ( A = '1' and B = '0' and C = '1' and D = '0' ) then

sum<= '0'

else

if ( A = '1' and B = '0' and C = '1' and D = '1' ) then

sum<= '1'

else

if ( A = '1' and B = '1' and C = '0' and D = '0' ) then

sum<= '0'

else

if ( A = '1' and B = '1' and C = '0' and D = '1' ) then

sum<= '1'

else

if ( A = '1' and B = '1' and C = '1' and D = '0' ) then

sum<= '1'

else

if ( A = '1' and B = '1' and C = '1' and D = '1' ) then

sum<= '0'

else

sum <= 'X' ;

end if;

END PROCESS;

END functional;

i have made this VHDL code is it correct?!

Library ieee;

Use ieee.std_logic_1164.all;

ENTITY adder IS

generic (dummy : time := 0 ns);

PORT( A,B,C,D : IN std_logic;

sum: OUT std_logic);

END ENTITY;

ARCHITECTURE functional OF adder IS

BEGIN

PROCESS(A,B,C,D)

BEGIN

if ( A = '0' and B = '0' and C = '0' and D = '0' ) then

sum<= '0'

else

if ( A = '0' and B = '0' and C = '0' and D = '1' ) then

sum<= '1'

else

if ( A = '0' and B = '0' and C = '1' and D = '0' ) then

sum<= '1'

else

if ( A = '0' and B = '0' and C = '1' and D = '1' ) then

sum<= '0'

else

if ( A = '0' and B = '1' and C = '0' and D = '0' ) then

sum<= '1'

else

if ( A = '0' and B = '1' and C = '0' and D = '1' ) then

sum<= '0'

else

if ( A = '0' and B = '1' and C = '1' and D = '0' ) then

sum<= '0'

else

if ( A = '0' and B = '1' and C = '1' and D = '1' ) then

sum<= '1'

else

if ( A = '1' and B = '0' and C = '0' and D = '0' ) then

sum<= '1'

else

if ( A = '1' and B = '0' and C = '0' and D = '1' ) then

sum<= '0'

else

if ( A = '1' and B = '0' and C = '1' and D = '0' ) then

sum<= '0'

else

if ( A = '1' and B = '0' and C = '1' and D = '1' ) then

sum<= '1'

else

if ( A = '1' and B = '1' and C = '0' and D = '0' ) then

sum<= '0'

else

if ( A = '1' and B = '1' and C = '0' and D = '1' ) then

sum<= '1'

else

if ( A = '1' and B = '1' and C = '1' and D = '0' ) then

sum<= '1'

else

if ( A = '1' and B = '1' and C = '1' and D = '1' ) then

sum<= '0'

else

sum <= 'X' ;

end if;

END PROCESS;

END functional;

Last edited: