Skip navigation.
Home

comparator 3bits

// Design Name : comparator 3bits 
   // File Name   : comparator 3bits .v
  // Function    : description low level of  comparator 3bits  
  // Coder       : BOURAOUI KACEM
// one bit comparator 
module comparateur1bit (a,b,eq,asup,ainf);
// the  two  inputs to compare 
input  a,b ;
// eq=1 if a=b , asup=1 if a>b, ainf=1 if a<b
output eq,asup,ainf;
// 
assign eq = (a & b)| ( ~a & ~b);
assign asup = ~b & a;
assign ainf = b & ~a;
 
endmodule
 
module comparateur3bit(a,b,eq,asup,ainf);
input [2:0] a,b;
output eq,asup,ainf;
wire eq0,asup0,ainf0,eq1,asup1,ainf1,eq2,asup2,ainf2,i,j,k,l,i1,j1,k1,e,f;
//instancier les modules
comparateur1bit comparator0(a[0],b[0],eq0,asup0,ainf0);
comparateur1bit comparator1(a[1],b[1],eq1,asup1,ainf1);
comparateur1bit comparator2(a[2],b[2],eq2,asup2,ainf2);
//result =?
and and1(e,eq0,eq1);
and and2(eq,eq2,e);
// a > ?
and and1(i,eq2,asup1);
and and2(j,eq2,eq1);
and and3(k,j,asup0);
or or1(l,asup2,i);
or or2(asup,l,k);
// a < ?
and and1(i1,eq2,ainf1);
and and2(j1,eq2,eq1);
and and3(k1,j1,ainf0);
or or1(l1,ainf2,i1);
or or2(ainf,l1,k1);
endmodule