| Gate | Function | Syntax |
|---|---|---|
and |
AND | and(out, in1, in2, ...) |
or |
OR | or(out, in1, in2, ...) |
nand |
NAND | nand(out, in1, in2) |
nor |
NOR | nor(out, in1, in2) |
xor |
XOR | xor(out, in1, in2) |
xnor |
XNOR | xnor(out, in1, in2) |
not |
Inverter | not(out, in) |
buf |
Buffer | buf(out, in) |
Gate Instantiation
module gates_example (
input wire a, b, c,
output wire y1, y2, y3
);
// Basic gates (output first, then inputs)
and g1 (y1, a, b); // y1 = a AND b
or g2 (y2, a, b, c); // y2 = a OR b OR c (multi-input)
nand g3 (y3, a, b); // y3 = NOT(a AND b)
// Multiple outputs from one gate type
not (out1, in1), (out2, in2); // Two inverters
endmodule