Вы находитесь на странице: 1из 4

VLSI CAD LAB

REPORT
SUBMITTED BY :RAJEN KUMAR PATRA
-14EC62D02

ROLL NO

Assignment -1
The number of nodes and the behavior of each node in
circuit is given. Write a progamme that will calculate the
output values of each nodes after taking the input from
the computer.
Solution: We are writing this programme in C language. We are taking the help of
user defined function to write this programme we are taking the help of user
defined function and defining the NAND, OR , NOT, NOR etc gates over there. We
are using the function strcmp to compare the input given by user to these standard
inputs. Whenever the user is assigning certain node as input the strcmp function
output becomes low and the Please enter input is printed and it is scanned
afterwords. Each node can be input itself and output of other node or nodes. So if
the node is not an input, then it can be the output of any other gate.
So we have to define the nodes which are not an input in this way.
Node 4= NAND 1 3
It means that Node 4 is output of a two input NAND gate whose inputs are node 1
and node 3.
For NOT gate we are realizing from the NAND function and two argument values we
are making equal.
Next we are taking the help of user defined functions where we are defining the
functions like AND, NAND etc. The statement like 4= NAND 1 3 here compares
NAND characters with an input defined string named NAND. When the strcmp
function makes the output low then NAND function is called and the values of node
1 and 3 goes to the function as an argument .
Here we have taken another variable u which will calculate the numbers of nodes
except the input node.

Let us take the statement:


x[i]=NAND(x[a[i]],x[b[i]]);
Here a[i] is keeping the input node number of the block in which i is the output
node number. And x[a[i]] is the value of the corresponding node number.

The complete programme is as follows,


#include<stdio.h>
#include<conio.h>
#include<string.h>
int NAND(int q,int r);
int NOR(int q,int r);
int OR(int q,int r);
int AND(int q,int r);
void main()
{
int i,u=1,k,p,n,s;
int a[10],b[10], d[10],e[10],f[10],g[10],h[10],j[10], x[10],y[10];
char a1[]="NAND"; char b1[]="nand";
char a2[]="NOR"; char b2[]= "nor ";
char a3[]="OR"; char b3[]= "or";
char a4[]="AND"; char b4[]= "and";
char a5[]="NOT"; char b5[]= "not";
char a6[]="INPUT";
char a7[]= "input";
char gate[10];
clrscr();
printf("Please enter the total number of nodes in the circuit\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("\n NODE %d::",i);
scanf("%s",gate);
d[i]=strcmp(a1,gate) && strcmp(b1,gate);
e[i]=strcmp(a2,gate) && strcmp(b2,gate);
f[i]=strcmp(a3,gate) && strcmp(b3,gate);
g[i]=strcmp(a4,gate) && strcmp(b4,gate);
h[i]=strcmp(a5,gate) && strcmp(b5,gate);
j[i]=strcmp(a6,gate);
y[i]=strcmp(a7,gate);
if(h[i]==0)
{
scanf("%d",&a[i]);
b[i]=a[i];
}
else if((j[i]==0)||(y[i]==0))
{
a[i]=100;b[i]=100;
}
else
scanf("%d %d",&a[i],&b[i]);
}
for(i=1;i<=n;i++)

{
if(a[i]==100 && b[i]==100)
{
printf("\n Please enter input %d::",i);
scanf("%d",&x[i]);
u++;
}
}
for(i=u;i<=n;i++)
{
if(d[i]==0)
x[i]=NAND(x[a[i]],x[b[i]]);
else if(e[i]==0)
x[i]=NOR(x[a[i]],x[b[i]]);
else if(f[i]==0)
x[i]=OR(x[a[i]],x[b[i]]);
else if(g[i]==0)
x[i]=AND(x[a[i]],x[b[i]]);
else
x[i]=NAND(x[a[i]],x[b[i]]);
}
printf("\n\t\tNODE NUMBERS\t\t\t OUTPUTS");
for(k=1;k<=n;k++)
{
printf("\n\t\t %d \t\t\t %d ",k,x[k]);
}
getch();
}
int NAND(int s,int r)
{
if(s==1 && r==1)
return 0;
else
return 1;
}
int NOR(int q,int r)
{
if(q==0 && r==0)
return 1;
else
return 0;
}
int OR(int q,int r)
{
if(q==0 && r==0)
return 0;
else
return 1;
}
int AND(int q,int r)
{
if(q==1 && r==1)
return 1;
else
return 0;

A typical ouput of the programme may look like that.

Вам также может понравиться