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 bit full adder in verilog

Status
Not open for further replies.

icaniwill

Junior Member level 3
Joined
Nov 9, 2007
Messages
26
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,283
Activity points
1,429
full adder verilog

i need to make a 4 bit full adder using verilog can anybody please help me?
 

yanzixuan

Member level 3
Joined
Feb 26, 2009
Messages
65
Helped
10
Reputation
20
Reaction score
6
Trophy points
1,288
Activity points
1,573
verilog full adder

icaniwill said:
i need to make a 4 bit full adder using verilog can anybody please help me?
Code:
module   full_adder_4bit(
    cin,
    cout,
    in_a,
    in_b,
    sum
    );
    
    parameter   reg_size = 4;
    
    input   cin;
    input   [reg_size-1:0] in_a;
    input   [reg_size-1:0] in_b;
    output  [reg_size-1:0] sum;
    output  cout;
    
    assign   {cout,sum} = in_a + in_b + cin;
    
endmodule
 
  • Like
Reactions: sntsh

    icaniwill

    Points: 2
    Helpful Answer Positive Rating

    sntsh

    Points: 2
    Helpful Answer Positive Rating

malikmuhammadali

Newbie level 5
Joined
Dec 16, 2008
Messages
8
Helped
4
Reputation
8
Reaction score
2
Trophy points
1,283
Activity points
1,342
This is code is for an simple asynchronous
wrapping n-bit adder. By changing the value
of n you can make it a 2, 4, … bit adder
where n = <number of bits> - 1. f is the output register that will have the current value of the counter, cOut is the carry output. a & b are the number inputs and cIn is the carry input. Both the number outputs and inputs are set by the value of n so you can add two n-bit numbers and a carry bit then get an n-bit number plus carry bit ou




module nBitAdder(f, cOut, a, b, cIn);
parameter n = 7;

output reg [n:0] f;
output reg cOut;
input [n:0] a;
input [n:0] b;
input cIn;

always @(a, b, cIn)
{cOut, f} = a + b + cIn;
endmodule
 
  • Like
Reactions: sntsh

    icaniwill

    Points: 2
    Helpful Answer Positive Rating

    sntsh

    Points: 2
    Helpful Answer Positive Rating

icaniwill

Junior Member level 3
Joined
Nov 9, 2007
Messages
26
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,283
Activity points
1,429
malikmuhammadali said:
This is code is for an simple asynchronous
wrapping n-bit adder. By changing the value
of n you can make it a 2, 4, … bit adder
where n = <number of bits> - 1. f is the output register that will have the current value of the counter, cOut is the carry output. a & b are the number inputs and cIn is the carry input. Both the number outputs and inputs are set by the value of n so you can add two n-bit numbers and a carry bit then get an n-bit number plus carry bit ou




module nBitAdder(f, cOut, a, b, cIn);
parameter n = 7;

output reg [n:0] f;
output reg cOut;
input [n:0] a;
input [n:0] b;
input cIn;

always @(a, b, cIn)
{cOut, f} = a + b + cIn;
endmodule

thanx alot
 
  • Like
Reactions: sntsh

    sntsh

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top