Verilog code for Comparator using NAND

2 bit Comparator using NAND:

 Using the circuit of 2-bit comparator, it is designed using NAND gate. Comparator compares the value between two variables, it gives the output as LESS, EQUAL OR GREATER. So here, 30 NAND gates are use to implement 2-bit comparator.







Verilog code for 2 bit Comparator using NAND:


module nand_2_bit_comparator(grt,equal,less,a1,b1,a0,b0); 
output grt,less,equal; 
input a1,b1,a0,b0; 
wire c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,x1,x2,x3; 
//equality 1stxnor  
nand n1(c,a1,b1); 
nand n2(d,a1,c); 
nand n3(e,b1,c); 
nand n4(f,d,e); 
nand n5(x1,f,f); 
//2nd xnor 
nand n6(g,a0,b0); 
nand n7(h,a0,g); 
nand n8(i,b0,g); 
nand n9(j,h,i); 
nand n10(x2,j,j); 
//and gate 
nand n11(x3,x1,x2); 
nand n12(equal,x3,x3); 
//greater 
nand n13(w,b1,b1); 
nand n14(k,a1,w); 
nand n15(y,b0,b0); 
nand n16(l,a0,y,x1); 
nand n17(n,l,l);
nand n18(m,k,k); 
nand n19(o,m,m); 
nand n20(p,n,n); 
nand n21(grt,o,p); 
//less
 nand n22(x,a0,a0); 
nand n23(q,x,b0); 
nand n24(z,a1,a1); 
nand n25(r,z,b1,x1); 
nand n26(s,q,q); 
nand n27(t,r,r); 
nand n28(u,s,s); 
nand n29(v,t,t); 
nand n30(less,u,v); 
endmodule   

OUTPUT:

















Post a Comment

0 Comments