DLCOA Lab Manual
DLCOA Lab Manual
Aim: To study and verify the Truth Tables of AND, OR, NOT, NAND, NOR, EXOR logic gates
Theory:
AND, AND, OR and NOT gates are basic gates. XOR and XNOR are universal gates.
Basically logic gates are electronic circuits because they are made up of number of electronic
devices and components. Inputs and outputs of logic gates can occur only in two levels. These
two levels are term HIGH and LOW, or TRUE and FALSE, or ON AND off, OR SIMPLY 1
AND 0. A table which lists all possible combinations of input variables and the corresponding
outputs is called a „truth table‟. It shows how the logic circuit‟s output responds to various
combinations of logic levels at the inputs.
AND GATE:-
An AND gate has two or more inputs but only one output. The output assumes the logic 1
state only when each one of its inputs is at logic 1 state. The output assumes logic 0 state even if
one of its input is at logic 0 state. AND gate is also called an „all or nothing‟ gate.
The logic symbol & truth table of two input AND gate are shown in figure 1.a & 1.b
respectively. The symbol for AND operation is „.‟.
With input variables A & B the Boolean expression for output can be written as;
X = A.B
Input Output
1
A 3 A B X
2
X
B 0 0 0
X = AB
0 1 0
1 0 0
1 1 1
Fig.1.a Fig.1.b
Pin diagram of IC74LS08:
OR GATE
Like an AND gate, an OR gate may have two or more inputs but only one output. The
output assumes the logic 1 state, even if one of its inputs is in logic 1 state. Its output assumes
logic 0 state, only when each one of its inputs is in logic 0 state. OR gate is also called an „any or
all‟ gate. It can also be called an inclusive OR gate because it includes the condition „both the
input can be present‟.
The logic symbol & truth table of two input OR gate are shown in figure 1.c & 1.d
respectively. The symbol for OR operation is „+‟.
With input variables A & B the Boolean expression for output can be written as;
X=A+B
Input Output
1
A 3
2
X A B X
B
X= A+ B 0 0 0
0 1 1
1 0 1
1 1 1
Fig.1.c Fig.1.d
A NOT gate is also known an inverter, has only one input and only one output. It is a
device whose output is always the complement of its input. That is the output of a not gate
assumes the logic 1 state when its input is in logic 0 state and assumes the logic 0 state when its
input is in logic 1 state.
The logic symbol & truth table of NOT gate are shown in figure 1.e & 1.f respectively.
The symbol for NOT operation is „-„-‟(bar).
With input variable A the Boolean expression for output can be written as;
Input Output
A X
0 1
1 0
Fig.1.e Fig.1.f
Pin diagram for IC74LS04:
NAND GATE
NAND gate is universal gate. It can perform all the basic logic function. NAND means
NOT AND that is, AND output is NOTed.so NAND gate is combination of an AND gate and a
NOT gate. The output is logic 0 level, only when each of its inputs assumes a logic 1 level. For
any other combination of inputs, the output is logic 1 level. NAND gate is equivalent to a
bubbled OR gate.
The logic symbol & truth table of two input NAND gate are shown in figure 1.g & 1.h
respectively.
̅̅̅̅̅
Input Output
A 1 A B X
3
2
X
B 0 0 1
X = AB 0 1 1
1 0 1
1 1 0
Fig.1.g Fig.1.h
Pin diagram for IC74LS00:
NOR GATE
NOR gate is universal gate. It can perform all the basic logic function. NOR means NOT
OR that is, OR output is NOTed.so NOR gate is combination of an OR gate and a NOT gate. The
output is logic 1 level, only when each of its inputs assumes a logic 0 level. For any other
combination of inputs, the output is logic 0 level. NOR gate is equivalent to a bubbled AND
gate. The logic symbol & truth table of two inputs NOR gate are shown in figure 1.i& 1.j
respectively. With input variables A & B the Boolean expression for output can be written as;
̅̅̅̅̅̅̅̅
Input Output
A B X
A 2
1
X 0 0 1
3
B
0 1 0
X= A+ B
1 0 0
1 1 0
Fig.1.i Fig.1.j
Pin diagram for IC74LS02:
An X-OR gate is a two input, one output logic circuit, whose output assumes a logic 1 state
when one and only one of its two inputs assumes a logic 1 state. Under the condition when both
the inputs are same either 0 or 1, the output assumes a logic 0 state. Since an X-OR gate
produces an output 1 only when the inputs are not equal, it is called as an anti-coincidence gate
or inequality detector. The output of an X-OR gate is the modulo sum of its two inputs. The logic
symbol & truth table of two input X-OR gate are shown in figure 1.k & 1.l respectively. The
symbol for X-OR operation is „⊕‟. With input variables A & B the Boolean expression for
output can be written as;
X= A ⊕
Input Output
A B X
1
A 3
2
X
B 0 0 0
0 1 1
X= A ⊕
1 0 1
1 1 0
Fig.1.k Fig.1.l
Pin diagram for IC74LS86:
Procedure:-
AND Gate: The output of an AND gate is only 1 if both its inputs are 1. For all other possible
inputs the output is 0.When both the LEDS are On, then output LED is ON (RED Light)
otherwise Output LED is OFF.
NOR Gate: The output of the NOR gate is a 1 if both inputs are 0 but a 0 if one or the other or
both the inputs are 1.
NAND Gate: The output of the NAND gate is a 0 if both inputs are 1 but a 1 if one or the other
or both the inputs are 0.
EXOR gate: The output of the XOR gate is a 1 if either but not both inputs are 1 and a 0 if the
inputs are both 0 and both 1.
Conclusion: Any Boolean expression can be realized using NOT, AND, OR, NAND,NOR,
EXOR gates.
Experiment No.2
Theory:-
Universal gates: -
The Nand and Nor gates are called as universal gates, because it is possible to implement any
Boolean expression with the help of only Nand or only Nor gates.
Hence a user can build any combinational circuit with the help of only Nand gates or only Nor
gates.
The NAND & NOR gates are called as „Universal gates‟. Because it is possible to
implement any Boolean expression with the help of only NAND or only NOR gate. We can
construct AND, OR, NOT, X-OR & X-NOR gates.
This is a great advantage because a user will have to make a stock of only Nand or Nor gates.
A
𝐴
But ̿
Y=A.B
This equation can be realized using only NAND gate as shown in fig.
A
A.B
B
3) OR using NAND:-
The Boolean expression for an OR gate is Y=A + B
Taking double inversion,
̿̿̿̿̿̿̿
But by DE-Morgan‟s theorem
̅̅̅̅̅̅̅ ̅ ̅
̅̅̅̅̅
̅ ̅
This is required expression for OR gate
A+B
B
4) NOR using NAND:-
The Boolean expression for an NOR gate is ̅̅̅̅̅̅̅̅̅
̅̅̅̅̅̅̅ ̅ ̅
̅ ̅
Taking double inversion,
̿̿̿̿̿
̅ ̅
This is required expression for NOR gate
A
̅̅̅̅̅̅
B
5) Ex-OR using NAND:-
The expression for Ex- OR gate is
⊕
̅ ̅
Taking double inversion
̿̿̿̿̿̿̿̿̿̿̿̿̿̿
̅ ̅
Let ̅ =X and ̅ =Z
=̿̿̿̿̿̿̿
i g e g he e
̅̅̅̅̅̅̅ ̅ ̅
̅̅̅̅̅
̅ ̅
̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅
̅̅̅̅̅
̅ ̅̅̅̅̅̅̅̅
̅̅̅
This is required expression for Ex-OR gate using NAND gate.
̅ ̅
A ̅
2) OR using NOR:-
The Boolean expression for an OR gate is Y=A+B
Taking double inversion,
̿̿̿̿̿̿̿
But ̿
Y=A+B
This equation can be realized using only NAND gate as shown in fig.
A A+B
A.B
̅̅̅̅̅ ̅ ̅
̅ ̅
Taking double inversion,
̿̿̿̿̿̿̿
̅ ̅
This is required expression for NAND gate
A
̅̅̅̅̅
=̿̿̿̿̿̿̿
i g e g he e
̅̅̅̅̅̅̅ ̅ ̅
̅̅̅̅̅
̅ ̅
̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅
̅̅̅̅̅̅̅̅
̅ ̅̅̅̅̅̅̅̅
̅̅̅
But ̅̅̅̅̅
̅ ̅ and ̅̅̅ ̅
̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅
̅ ̅
̅̅̅̅̅̅̅̅̅̅̅
̅ ̅̅̅̅̅̅̅̅̅̅
̅
̿̿̿̿̿̿̿̿̿̿̿̿̿̿̿̿̿̿̿̿̿̿̿̿̿
̅̅̅̅̅̅̅̅̅̅̅
̅ ̅̅̅̅̅̅̅̅̅̅
̅
𝐴𝐵 𝐴 𝐵̅
Conclusion:-
All the gates are realized using NAND and NOR gates and truth tables are verified.
Experiment No.3
Components: - IC 7486
Theory:
Gray code is a non-weighted code. It is not an arithmetic code. It has a very special
feature that only one bit in the gray code will change, each time the decimal number is
incremented. As only one bit changes at a time, the gray code is called „unit distance code‟. The
gray code is cyclic code is also exhibits the reflective property.
G3 = B3
⊕
K-Map for G0:
TRUTH TABLE:
B3 B2 B1 B0 G3 G2 G1 G0
0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 1
0 0 1 0 0 0 1 1
0 0 1 1 0 0 1 0
0 1 0 0 0 1 1 0
0 1 0 1 0 1 1 1
0 1 1 0 0 1 0 1
0 1 1 1 0 1 0 0
1 0 0 0 1 1 0 0
1 0 0 1 1 1 0 1
1 0 1 0 1 1 1 1
1 0 1 1 1 1 1 0
1 1 0 0 1 0 1 0
1 1 0 1 1 0 1 1
1 1 1 0 1 0 0 1
1 1 1 1 1 0 0 0
Conclusion:-
LEARNING OBJECTIVE:
To design, realize and verify the adder and subtractor circuits using basic gates and
universal gates.
To design, realize and verify full adder using two half adders.
To design, realize and verify a full subtractor using two half subtractors.
COMPONENTS REQUIRED: IC 7400, IC 7408, IC 7486, and IC 7432, Patch cards and IC
Trainer Kit.
THEORY:
Half-Adder: A combinational logic circuit that performs the addition of two data bits, A and B,
is called a half-adder. Addition will result in two output bits; one of which is the sum bit, S, and
the other is the carry bit, C. The Boolean functions describing the half-adder are:
S =A ⊕ B C=AB
Full-Adder: The half-adder does not take the carry bit from its previous stage into account. This
carry bit from its previous stage is called carry-in bit. A combinational logic circuit that adds
two data bits, A and B, and a carry-in bit, Cin, is called a full-adder. The Boolean functions
describing the full-adder are:
S = (x ⊕ y) ⊕ Cin C = xy + Cin (x ⊕ y)
Half Subtractor: Subtracting a single-bit binary value B from another A (i.e. A -B) produces a
difference bit D and a borrow out bit B-out. This operation is called half subtraction and the
circuit to realize it is called a half subtractor. The Boolean functions describing the
halfSubtractor are:
S =A ⊕ B C = A’ B
Full Subtractor: Subtracting two single-bit binary values, B, Cin from a single-bit value A
produces a difference bit D and a borrow out Br bit. This is called full subtraction. The Boolean
functions describing the full-subtracter are:
D = (x ⊕ y) ⊕ Cin Br= A’B + A’ (Cin) + B (Cin)
I. TO REALIZE HALF ADDER
i) NAND GATES
INPUTS OUTPUT
A B D Br
0 0 0 0
0 1 1 1
1 0 1 0
1 1 0 0
IV. FULL SUBTRACTOR
RESULT:
Experiment No. 5
Theory:
Booth algorithm gives a procedure for multiplying binary integers in signed 2’s
complement representation in efficient way, i.e., less number of additions/subtractions
required in general. It operates on the fact that strings of 0’s in the multiplier require no
addition but just shifting and a string of 1’s in the multiplier from bit weight 2k to
weight 2mcan be treated as 2k+1 to 2m.
The Booth’s algorithm can be described using the following flowchart. We name the
register that keeps the partial product as A, the multiplicand as M, the multiplier as Q, the
extra bit Q−1 attached to Q0, which is the least significant bit of the multiplier, and the
counter as Count.
A and the appended bit Q−1 are initially cleared to 0 and the sequence Count is set to a
number n equal to the number of bits in the multiplier. The two bits of the multiplier
in Q0 and Q−1 are inspected. If the two bits are equal to 10, it means that the first 1 in a
string has been encountered. This requires subtraction of the multiplicand from the partial
product in A. If the 2 bits are equal to 01, it means that the first 0 in a string of 0’s has
been encountered. This requires the addition of the multiplicand to the partial product in
A.
When the two bits are equal, the partial product does not change. An overflow cannot
occur because the addition and subtraction of the multiplicand follow each other. As a
consequence, the 2 numbers that are added always have a opposite signs, a condition that
excludes an overflow. The next step is to shift right the partial product and the multiplier
(including Q−1). This is an arithmetic shift right (ashr) operation which A, Q, and Q−1
shifts to the right and leaves the sign bit in A unchanged. The sequence counter Count is
decremented and the computational loop is repeated n times.
Flowchart:
Program:
#include <stdio.h>
#include <conio.h>
#include <process.h>
#include <math.h>
int get(int a)
{ char ch =
'B'; int flag =
0; if (a == 1)
ch = 'A';
do {
printf("\nENTER VALUE OF %c: ", ch);
scanf("%d", & a);
if (a < 0) {
a = a * -1;
flag = 1;
}
if (9 <= a)
printf("│\n\t!INVALID NUMBER.ENTER VALUE (-9 < A < 9)!");
} while (9 <= a);
if (flag)
a = a * -1;
return (a);
}
void main() {
int q = 0, i, j, a, b, A[4] = {0,0,0,0}, C[4] = {0,0,0,1}, C1[8] = {0,0,0,0,0,0,0,1};
int s = 0, z = 0, Q[4], M[4], temp, temp1[4], ans[8], y, x = 0, c = 0;
//clrscr();
printf("\n Name: Anuj Ganesh Pathare");
printf("\n Roll No: 35 (SE)");
printf("\n Subject: DLCOA");
printf("\n--------BOOTH'S MULTIPLICATION ALGORITHM--------\n");
printf("\nBoth Numbers must be less than 9 and greater than -9");
//printf("\n│----------------------------------------------------\n");
a = get(1);
b = get(0);
//printf("\n│---------------------------------------------------\n");
binary(a, M);
binary(b, Q);
printf("\n\n---------------------------------------------------\n");
printf(" OPERATION\t\t A\t Q\tQ'\t M");
printf("\n\n INITIAL\t\t");
for (i = 0; i < 4; i++)
printf("%d", A[i]);
printf("\t");
for (i = 0; i < 4; i++)
printf("%d", Q[i]);
printf("\t");
printf("%d\t", q);
for (i = 0; i < 4; i++)
printf("%d", M[i]);
for (j = 0; j < 4; j++) {
if ((Q[3] == 0) && (q == 1)) {
printf("\n A:=A+M \t\t");
add(A, M);
for (i = 0; i < 4; i++)
printf("%d", A[i]);
printf("\t");
for (i = 0; i < 4; i++)
printf("%d", Q[i]);
printf("\t%d\t", q);
for (i = 0; i < 4; i++)
printf("%d", M[i]);
}
if ((Q[3] == 1) && (q == 0)) {
printf("\n A:=A-M \t\t");
for (i = 0; i < 4; i++)
temp1[i] = 1 - M[i];
add(temp1, C);
add(A, temp1);
for (i = 0; i < 4; i++)
printf("%d", A[i]);
printf("\t");
for (i = 0; i < 4; i++)
printf("%d", Q[i]);
printf("\t%d\t", q);
for (i = 0; i < 4; i++)
printf("%d", M[i]);
}
printf("\n Shift \t\t\t");
y = A[3];
q = Q[3];
rshift(A[0], A);
rshift(y, Q);
for (i = 0; i < 4; i++)
printf("%d", A[i]);
printf("\t");
for (i = 0; i < 4; i++)
printf("%d", Q[i]);
printf("\t");
printf("%d\t", q);
for (i = 0; i < 4; i++)
printf("%d", M[i]);
}
printf("\n\n---------------------------------------------------\n");
printf("\nTHE ANSWER IN BINARY IS : ");
for (i = 0; i < 4; i++)
ans[i] = A[i];
for (i = 0; i < 4; i++)
ans[i + 4] = Q[i];
if (((a < 0) && (b > 0)) || ((a > 0) && (b < 0))) {
for (i = 0; i < 8; i++)
ans[i] = 1 - ans[i];
for (i = 7; i >= 0; i--)
{ x = ans[i];
ans[i] = c ^ x ^ C1[i];
if (((c == 1) && (x == 1)) || ((x == 1) && (C1[i] == 1)) || ((C1[i] == 1) && (c == 1)))
c = 1;
else
c = 0;
}
}
for (i = 0; i < 8; i++)
printf("%d", ans[i]);
for (i = 7; i >= 0; i--) {
s = s + (pow(2, z) * ans[i]);
z = z + 1;
}
if (((a < 0) && (b > 0)) || ((a > 0) && (b < 0)))
printf("\nTHE ANSWER IN DECIMAL IS : -%d\n", s);
else
printf("\nTHE ANSWER IN DECIMAL IS : %d\n", s);
getch();
}
Output:
Experiment No. 6
Theory:
A division algorithm provides a quotient and a remainder when we divide two
number. They are generally of two type slow algorithm and fast algorithm. Slow division
algorithm are restoring, non-restoring, non-performing restoring, SRT algorithm and
under fast comes Newton–Raphson and Goldschmidt.
Restoring Division Algorithm is used to divide two unsigned integers. Restoring term is due
to fact that value of register A is restored after each iteration. Here, register Q contain
quotient and register A contain remainder. Here, n-bit dividend is loaded in Q and divisor is
loaded in M. Value of Register is initially kept 0 and this is the register whose value is
restored during iteration due to which it is named Restoring.
The number of steps required to compute the required quotient and remainder is equal to
the number of bits in the dividend. Initially, let the dividend be Q and the divisor be M and
the accumulator A = 0.
Therefore:
#include <stdio.h>
#include <conio.h>
#include <math.h>
int getsize(int x)
{
int c;
if(x <= 1)
c = 2;
else if(x < 4)
c = 2;
else if(x< 8)
c = 3;
else if(x< 16)
c = 4;
else if(x< 32)
c = 5;
else if(x< 64)
c = 6;
else if(x< 128)
c = 7;
else if(x< 256)
c = 8;
else if(x< 512)
c = 9;
return c;
}
void main()
{
int B,Q,Z,M,c,c1,e,f,g,h,i,j,x,y,ch,in,S,G,P;
int a[24],b[12],b1[12],q[12],carry=0,count=0,option;
long num;
do
{
//clrscr();
printf("\n Name: Anuj Ganesh Pathare");
printf("\n Roll No: 35 (SE)");
printf("\n Subject: DLCOA");
printf("\n--------RESTORING DIVISION ALGORITHM--------\n");
printf("\n\nENTER DIVIDEND\t: ");
scanf("%d",&Q);
y = getsize(Q);
printf("ENTER DIVISOR\t: ");
scanf("%d",&M);
x = getsize(M);
Z = max(x,y);
printf("\n\tTOTAL BITS CONSIDERED FOR RESULT => %d",2*Z+1);
printf("\n\tINITiALLY A IS RESET TO ZERO:");
for(i=0;i<=Z;i++)
printf("%d ",a[i]=0);
for(i=Z;i>=0;i--)
{
b1[i] = b[i] = M%2;
M = M/2;
b1[i] = 1-b1[i];
}
carry = 1;
for(i=Z;i>=0;i--)
{
c1 = b1[i]^carry;
carry = b1[i]&&carry;
b1[i]=c1;
}
for(i=2*Z;i>Z;i--)
{
a[i] = Q%2;
Q = Q/2;
}
printf("\n\n\tDivisor\t\t(M)\t: ");
for(i=0;i<=Z;i++)
printf("%d ",b[i]); printf("\n\t2'C
Divisor\t(M)\t: ");
for(i=0;i<=Z;i++)
printf("%d ",b1[i]);
printf("\n\tDividend\t(Q)\t: ");
for(i=Z+1;i<=2*Z;i++)
printf("%d ",a[i]);
printf("\n\n\tBITS CONSIDERED:[ A ] [ M ]");
printf("\n\t\t\t");
for(i=0;i<=Z;i++)
printf("%d ",a[i]);
printf(" ");
for(i=Z+1;i<=2*Z;i++)
printf("%d ",a[i]);
count = Z;
do{
for(i=0;i< 2*Z;i++)
a[i] = a[i+1];
printf("\n\nLeft Shift\t\t");
for(i=0;i<=Z;i++)
printf("%d ",a[i]);
printf(" ");
for(i=Z+1;i< 2*Z;i++)
printf("%d ",a[i]);
carry=0;
for(i=Z;i>=0;i--)
{
S=a[i]^(b1[i]^carry);
G=a[i]&&b1[i];
P=a[i]^b1[i];
carry=G||(P&&carry);
a[i]=S ;
}
printf("\nA< -A-M \t\t");
for(i=0;i<=Z;i++)
printf("%d ",a[i]);
printf(" ");
for(i=Z+1;i< 2*Z;i++)
printf("%d ",a[i]);
ch=a[0];
printf("\nBIT Q:%d",ch);
switch (ch)
{
case 0: a[2*Z]=1;
printf(" Q0< -1\t\t");
for(i=0;i<=Z;i++)
printf("%d ",a[i]);
printf(" ");
for(i=Z+1;i<=2*Z;i++)
printf("%d ",a[i]);
break;
case 1: a[2*Z]=0;
printf(" Q0< -0\t\t");
for(i=0;i<=Z;i++)
printf("%d ",a[i]);
printf(" ");
for(i=Z+1;i< 2*Z;i++)
printf("%d ",a[i]);
carry=0;
for(i=Z;i>=0;i--)
{
S=a[i]^(b[i]^carry);
G=a[i]&&b[i];
P=a[i]^b[i];
carry=G||(P&&carry);
a[i]=S ;
}
printf("\nA< -A+M");
printf("\t\t\t");
for(i=0;i<=Z;i++)
printf("%d ",a[i]);
printf(" ");
for(i=Z+1;i<=2*Z;i++)
printf("%d ",a[i]);
break;
}
count--;
}while(count!=0);
num=0;
printf("\n\t\t< < QUOTIENT IN BINARY>> :");
for(i=Z+1;i<=2*Z;i++)
{
printf("%d ",a[i]);
num=num+pow(2,2*Z-i)*a[i];
}
printf("\n\t\tOUOTIENT IN DECIMAL :%d",num);
num=0;
printf("\n\t\t< < REMAINDER IN BINARY>>:");
for(i=0;i<=Z;i++)
{
printf("%d ",a[i]);
num=num+pow(2,Z-i)*a[i];
}
printf("\n\t\tREMAINDER IN DECIMAL :%d",num);
getche();
printf("\n\tDO YOU WANT TO CONTINUE PRESS 0-ESC 1-CONT.:");
scanf("%d",&option);
}while(option!=0);
getch();
}
Output:
Experiment No. 7
Theory:
In Non-Restoring division, it is less complex than the restoring one because simpler
operation are involved i.e. addition and subtraction, also now restoring step is performed. In
the method, rely on the sign bit of the register which initially contain zero named as A.
Non-restoring division algorithm is used to divide two unsigned integers. The other form of
this algorithm is Restoring Division. This algorithm is different from the other algorithm
because here, there is no concept of restoration and this algorithm is less complex than the
restoring division algorithm.
The number of steps required to compute the required quotient and remainder is equal to
the number of bits in the dividend. Initially, let the dividend be Q and the divisor be M and
the accumulator A = 0. Therefore:
1. At each step, left shift the dividend by 1 position.
2. Subtract the divisor from A (A – M).
3. If the result is positive then the step is said to be “successful”. In this case,
the quotient bit will be “1” and the restoration is NOT Required. So, the next
step will also be subtraction.
4. If the result is negative then the step is said to be “unsuccessful”. In this case,
the quotient bit will be “0”. Here, the restoration is NOT performed like the
restoration division algorithm. Instead, the next step will be ADDITION in
place of subtraction.
5. Repeat steps 1 to 4 for all bits of the Dividend.
Flowchart:
Program:
#include <stdio.h>
#include <conio.h>
void comp()
{ int i = 4;
do {
b2c[i] = b[i];
i--;
} while (b[i + 1] != 1);
while (i >= 0) {
b2c[i] = (b[i] + 1) % 2;
i--;
}
printf("\n\tDivisor's complement:");
for (i = 0; i < 5; i++)
printf("%d", b2c[i]);
printf("\n");
}
void nonresdiv()
{ shiftleft();
if (a[0] == 0)
a_minus_b();
else
a_plus_b();
q[3] = (a[0] + 1) % 2;
}
void shiftleft()
{ int i;
for (i = 0; i < 4; i++)
a[i] = a[i + 1];
a[4] = q[0];
for (i = 0; i < 3; i++)
q[i] = q[i + 1];
}
void a_minus_b() {
int i, carry = 0, sum = 0;
for (i = 4; i >= 0; i--) {
sum = (a[i] + b2c[i] + carry);
a[i] = sum % 2;
carry = sum / 2;
}
}
void a_plus_b() {
int i, carry = 0, sum = 0;
for (i = 4; i >= 0; i--) {
sum = (a[i] + b[i] + carry);
a[i] = sum % 2;
carry = sum / 2;
}
}
void main()
{ int i, j, k;
//clrscr();
printf("\n Name: Anuj Ganesh Pathare");
printf("\n Roll No: 35 (SE)");
printf("\n Subject: DLCOA");
printf("\n--------NON-RESTORING DIVISON ALGORITHM--------\n");
printf("\nEnter dividend in binary form\t: ");
for (i = 0; i < 4; i++)
scanf("%d", & q[i]);
printf("\nEnter divisor in binary form\t: ");
for (i = 0; i < 5; i++)
scanf("%d", & b[i]);
comp();
printf("\n\t[A]\t[M]\n");
for (i = 0; i < 4; i++) {
nonresdiv();
printf("\t");
for (j = 0; j < 5; j++)
printf("%d", a[j]);
printf("\t");
for (k = 0; k < 4; k++)
printf("%d", q[k]);
printf("\n");
}
if (a[0] == 1)
a_plus_b();
printf("\t");
for (j = 0; j < 5; j++)
printf("%d", a[j]);
printf("\t");
for (k = 0; k < 4; k++)
printf("%d", q[k]);
printf("\n");
printf("\n\tThe Quotient Is\t: ");
for (k = 0; k < 4; k++)
printf("%d", q[k]);
printf("\n\tThe Remainder Is: ");
for (j = 0; j < 5; j++)
printf("%d", a[j]);
getch();
}
Output:
Experiment No. 8
Design Issues :
The circuit functionality of a 1 bit ALU is shown here, depending upon the control signal
S1 and S0 the circuit operates as follows:
Circuit Diagram:-
The circuit diagram of 4 bit ALU.
Procedure:-
1. Start the simulator as directed.This simulator supports 5-valued logic.
2. To design the circuit we need 4 1-bit ALU, 11 Bit switch (to give input,which will
toggle its value with a double click), 5 Bit displays (for seeing output), wires.
3. The pin configuration of a component is shown whenever the mouse is hovered on any
canned component of the palette. Pin numbering starts from 1 and from the bottom left
corner (indicating with the circle) and increases anticlockwise.
4. For 1-bit ALU input A0 is in pin-9,B0 is in pin-10, C0 is in pin-11 (this is input carry),
for selection of operation, S0 is in pin-12, S1 is in pin-13, output F is in pin-8 and output
carry is pin-7
5. Click on the 1-bit ALU component (in the Other Component drawer in the pallet) and
then click on the position of the editor window where you want to add the component (no
drag and drop, simple click will serve the purpose), likewise add 3 more 1-bit ALU (from
the Other Component drawer in the pallet), 11 Bit switches and 5 Bit Displays (from
Display and Input drawer of the pallet,if it is not seen scroll down in the drawer), 3 digital
display and 1 bit Displays (from Display and Input drawer of the pallet,if it is not seen
scroll down in the drawer)
6. To connect any two components select the Connection menu of Palette, and then click
on the Source terminal and click on the target terminal. According to the circuit diagram
connect all the components. Connect the Bit switches with the inputs and Bit displays
component with the outputs. After the connection is over click the selection tool in the
pallete.
7. See the output, in the screenshot diagram we have given the value of S1 S0=11 which
will perform add operation and two number input as A0 A1 A2 A3=0010 and B0 B1 B2
B3=0100 so get output F0 F1 F2 F3=0110 as sum and 0 as carry which is indeed an add
operation.you can also use many other combination of different values and check the
result. The operations are implemented using the truth table for 4 bit ALU given in the
theory.
Output :-
Result:
Four bit Arithmetic Logic Unit (ALU) is designed and simulated using logic gates.
Experiment No. 9
Theory:-
Design of Memory :
Design Issues :
A basic RAM cell has been provided here as a component which can be used to design
larger memory units. An IC memory consisting of 4 words each having 3 bits has been
aslo provided.
Circuit diagram of 4X4 RAM memory:
Procedure:-
Design of 4X4 RAM memory:
1. Start the simulator as directed.This simulator supports 5-valued logic.
2. To design the circuit we need 12 binary RAM cell, 9 OR gate, 7 bit switch (to give
input,which will toggle its value with a double click), 3 bit display (to see the output),
wires.
3. The pin configuration of a component is shown whenever the mouse is hovered on any
canned component of the palette or press the 'show pinconfig' button. Pin numbering
starts from 1 and from the bottom left corner (indicated with the circle) and increases
anticlockwise.
4. For a binary RAM cell input is in pin-5, output is in pin-4 and select is pin-8,
Read/Write is in pin-6, for read operation give 1 input to Read/Write pin. For write
operation give 0 input to Read/Write pin.
5. For a 'decoder with enable', input A is in pin-6, B is in pin-5, output D0 is in pin-4, D1
is in pin-3, D2 is in pin-2, D3 is in pin-1 and Enable is in pin-8
6. Click on the 'decoder with enable' component (in the Other Components drawer in the
pallet) and then click on the position of the editor window where you want to add the
component (no drag and drop, simple click will serve the purpose), likewise add 12
binary RAM cell (from the Other Components drawer in the pallet), 9 OR gates (from
Logic Gates drawer in the pallete), 7 bit switches (which will toggle its value with a
double click), 3 bit displays (from Display and Input drawer of the pallet,if it is not seen
scroll down in the drawer)
7. To connect any two components select the Connection menu of Palette, and then click
on the Source terminal and click on the target terminal. According to the circuit diagram
connect all the components, connect 2 bit switches to the inputs of the 'decoder with
enable' (which will act as address input), 1 bit switch to the enable pin of the 'decoder
with enable' (which will act as memory enable input), connect a bit switch to the
Read/Write(R/W') line, 3 bit switches to the data inputs line, 3 bit displays to the data
output line and OR gates according to the diagram shown in the circuit diagram. after athe
connection is over click the selection tool in the pallete.
8. To see the circuit working, Do some read or write operation by properly setting the
R/W', memory enable then give input and check the output. suppose you give, R/W'=1,
memory enable=1, address input=01, data input=101, then it will be a read operation and
you will not see 101 as output, it will store 101 in the word-1. now again set, R/W'=0,
memory enable=1, address input=01, then it will be a write operation and you will see
101 as the content of word-1 on the output display.
Output:-
Result:
The memory design has been implemented using logic gates.
Experiment No: 10
Aim: - To implement Ripple Carry Adder using Virtual Lab.
Theory: -
Arithmetic operations like addition, subtraction, multiplication, division are basic operations to be
implemented in digital computers using basic gates like AND, OR, NOR, NAND etc. Among all the
arithmetic operations if we can implement addition then it is easy to perform multiplication (by
repeated addition), subtraction (by negating one operand) or division (repeated subtraction).
Half Adders can be used to add two one bit binary numbers. It is also possible to create a logical
circuit using multiple full adders to add N-bit binary numbers. Each full adder inputs a Can, which is
the Count of the previous adder. This kind of adder is a Ripple Carry Adder, since each carry bit
"ripples" to the next full adder. The first (and only the first) full adder may be replaced by a half
adder. The block diagram of 4-bit Ripple Carry Adder is shown here below –
The layout of ripple carry adder is simple, which allows for fast design time; however, the ripple
carry adder is relatively slow, since each full adder must wait for the carry bit to be calculated from
the previous full adder. The gate delay can easily be calculated by inspection of the full adder circuit.
Each full adder requires three levels of logic. In a 32-bit [ripple carry] adder, there are 32 full adders,
so the critical path (worst case) delay is 31 * 2(for carry propagation) + 3(for sum) = 65 gate delays.
Design Issues:
The corresponding Boolean expressions are given here to construct a ripple carry adder. In the half
adder circuit, the sum and carry bits are defined as
sum = A ⊕ B
carry = AB
In the full adder circuit, the Sum and Carry output is defined by inputs A, B and Carrying as
Having these we could design the circuit. But, we first check to see if there are any logically
equivalent statements that would lead to a more structured equivalent circuit.
= (A ⊕ B) C + (A ⊕ B) C
=A ⊕ B ⊕ C
= AB + (AB + AB) C
= AB + (A ⊕ B) C
Procedure: -
Output: -