## Gate Level Modeling

 Gate Level Modeling

Although the circuit behaviour in verilog is normally specified using assignment statements, in some cases modeling the circuit using primitive gates is done to make sure that the critical sections of circuit is most optimally laid out.

Verilog has built in primitives like gates, transmission gates, and switches to model gate level simulation. To see how the gate level simulation is done we will write the Verilog code that that we used for comparator circuit using primitive gates.

 `module gate( input x, input y, output z ); wire x_, y_, p,q; not(x_, x); not(y_, y); and(p, x,y); and(q, x_,y_); or(z,p,q); endmodule`

This example does the same fuction as the previous example, but we have used primitive gates in this example

 Explanation

The primitive

not (x_, x);

creates a not gate with x as input and x_ as output. All primitives has at least two parameters. The first parameter is output and other parameters are input. The statement

and(p, x,y);

creates an AND gate with two inputs and one output.

You can simulate the code with same stimulus that we did in the previous example, which is reproduced here.

 `initial begin // Initialize Inputs x = 0; y = 0;  // Wait 100 ns for global reset to finish #100; #50 x = 1; #60 y = 1; #70 y = 1; #80 x = 0; end`

And it produces the same output
``````
x=0,y=0,z=1
x=1,y=0,z=0
x=1,y=1,z=1
x=0,y=1,z=0
```
```

In the