Sei sulla pagina 1di 8

Experiment 1

Aim- Designing of 4 Bit Adder cum Subtractor using Gate Level Modelling Style.

Tool Used- Cadence NCSim

Platform- Red Hat Linux

Theory-

In digital circuits, an adder–subtractor is a circuit that is capable


of adding or subtracting numbers (in particular, binary). Addition and
subtraction can be done using a control signal. It is also possible to construct
a circuit that performs both addition and subtraction at the same time. In this
report we will discuss the circuit which uses additional XOR gates to perform
addition and subtraction. But first of all we will learn about the basic blocks
that are used to build an adder-subtractor circuit.

Full Adder:
A full adder adds binary numbers and accounts for values carried in as well
as out. A one-bit full-adder adds three one-bit numbers, often written as A, B,
and Cin , A and B are the operands, and Cin is a bit carried in from the previous
less-significant stage.

A B Cin S Cout

0 0 0 0 0

0 0 1 1 0

0 1 0 1 0

0 1 1 0 1

1 0 0 1 0

1 0 1 0 1

1 1 0 0 1

1 1 1 1 1

Truth Table for Full Adder

Consequent Sum and Carry equations are given as:


Circuit Diagram of Full adder :

Full Subtractor:

The full subtractor is a  combinational circuit  which is used to perform


subtraction of three input bits: the minuend X , subtrahend Y , and borrow in
Bin. The full subtractor generates two output bits: the difference D  and borrow
out BOUT .

X Y Bin D Bout

0 0 0 0 0

0 0 1 1 1

0 1 0 1 1

0 1 1 0 1

1 0 0 1 0

1 0 1 0 0

1 1 0 0 0

1 1 1 1 1

Truth Table for Full Subtractor

Consequent Difference and Borrow equations are given as:

D= X⊕Y⊕Bin
BOUT = X'Bin+X'Y+YBin
Circuit Diagram of Full Subtractor :

XOR gate:
Below the figure shows the symbol of xor gate with A and B as inputs and Q
as output. And Truth table is for the same is also given below.

Symbol of XOR gate

Truth Table of XOR gate:

A B Q

0 0 0

0 1 1

1 0 1

1 1 0

So we can see from the truth table dat if we hold the one input of XOR gate
to be 1 then it can act as not gate if the second input is 0. And if the hold the
first input to 0 then it acts as a buffer passing on the second input as it is. So
this logic can be used to build a adder subtractor circuit.
Ripple Carry Adder:

It is possible to create a logical circuit using multiple full adders to add N-bit


numbers. Each full adder inputs a Cin, which is the Cout of the previous adder.
This kind of adder is called a ripple-carry adder, since each carry bit "ripples"
to the next full adder. Note that the first (and only the first) full adder may be
replaced by a half adder (under the assumption that Cin = 0).

4-bit Ripple Carry Adder

Now that we have learnt how about all the basic things that are required for
an adder subtractor circuit. We will design a adder subtractor circuit using
these only.

Circuit Diagram of 4-bit Adder Subtractor:

Ci

Cout
Verilog Code:

module addsub (out1,out2,a,b,cin,sel);


input a,b,cin,sel;
output out1,out2;
wire w1,w2,w3,w4,w5;
xor x1(w1,a,sel);
xor x2(w2,a,b);
xor x3(out1,cin,w2);
and a1(w3,b,w1);
and a2(w4,b,cin);
and a3(w5,w1,cin);
or o1(out2,w3,w4,w5);
endmodule

module addsub_4 (cout,sum,a,b,cin,sel);


input [3:0] a,b;
input cin,sel;
output [3:0]sum;
output cout;
wire [2:0]c;
addsub a1(sum[0],c[0],a[0],b[0],cin,sel);
addsub a2(sum[1],c[1],a[1],b[1],c[0],sel);
addsub a3(sum[2],c[2],a[2],b[2],c[1],sel);
addsub a4(sum[3],cout,a[3],b[3],c[2],sel);
endmodule

//—————————test bench—————————

module addsubtb();
reg [3:0]a,b;
reg cin,sel;
wire [3:0]sum;
wire cout;
addsub_4 a5 (cout,sum,a,b,cin,sel);
initial
begin
a=4'b0000;b=4'b0000;cin=1;sel=0;
#5 a=4'b0001;b=4'b1101;cin=1;sel=0;
#5 a=4'b1110;b=4'b1111;cin=0;sel=0;
#5 a=4'b1110;b=4'b0110;cin=1;sel=0;
#5 a=4'b1010;b=4'b1111;cin=0;sel=1;
#5 a=4'b1100;b=4'b0011;cin=0;sel=1;
#5 a=4'b1001;b=4'b0011;cin=1;sel=1;
#10 $stop;
end
endmodule

Results:

Waveform of adder cum subtractor

RTL of Adder cum Subtractor


Conclusions:
After the completion of this experiment we get to know about the adder and
subtractor circuits and one circuit that can perform both the addition and
subtraction hence decreases the area. Also, we learnt abt the RTL of the
adder cum subtractor circuit.

Potrebbero piacerti anche