Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

4 input adder in VHDL adder

Status
Not open for further replies.

killersbeez

Newbie level 3
Joined
Jun 14, 2011
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,312
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;
 
Last edited:

I assume you are starting out, maybe for a class, in which case the Ripple Carry Adder is the one you would be seaching for.

VHDL: Ripple-Carry Adder

and this explains the ripple carry adder

**broken link removed**)

that should help.
 
says this for me and i cant find what wrong there :(
digi.vhdl: in adder(functional):
digi.vhdl:64: syntax error, unexpected t_PROCESS, expecting t_IF at PROCESS
v2cc: digi.vhdl: 1 errors

---------- Post added at 00:45 ---------- Previous post was at 00:27 ----------

find the problem! everything works, but is it a 4 input adder or its something other?!
 

This line shows the number of inputs:

IN STD_LOGIC_VECTOR(7 DOWNTO 0)

this is a 8bit adder. The ripple adder can be cascaded to as many bits as you would like. If you read the reference link above, and the for loop is causing confusion, try reading this example.

VHDL coding tips and tricks: 4 bit Ripple Carry Adder using basic logic gates

This is a gate level 4bit adder and test bench to simulate its behavior.

---------- Post added at 18:31 ---------- Previous post was at 18:15 ----------

O wooo ... did not see your code at the top. Where did that come from?
 

hi
in your program their is no carry and instead of "if" you can use "case" would be better..
if you want to use "else if" better to use "elsif"....


you may be getting error in your code because you used so many "if" and one "end if"
https://www.edaboard.com/threads/190952/
 
Last edited:

One suggestion, VHDL offers elsif. So instead of using else if every time you can use elsif. The code will look cleaner and easy to debug.

You have used many "else if" in the above code, but doesnt have enough "end if" to cover them all.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top