Magnitude Comparator

Download Report

Transcript Magnitude Comparator

Cascading 1-Bit Comparators
Discussion D7.0
A 1-Bit Comparator
xi
Gin
Ein
yi
1-bit
comparator
Gout
Eout
The variable Gout is 1 if Gin = 1 or if Ein = 1 and x > y.
The variable Eout is 1 if Ein = 1 and x = y.
module comp4 ( x, y, gt, eq, lt );
input [3:0] x ;
wire [3:0] x ;
input [3:0] y ;
wire [3:0] y ;
A 4-Bit Comparator
output lt ;
wire lt ;
output gt ;
wire gt ;
output eq ;
wire eq ;
x3
Gin=0
y3
G4
x2
E4
1 1 0 1
1 0 1 1
y2
x1
comp1bit
U2
E3
y1
G2
G3
comp1bit
U3
Ein=1
x
y
x0
G1
comp1bit
U1
E2
y0
G0
gt
comp1bit
U0
E1
eq
E0
lt
A 4-Bit Comparator
x3
Gin=0
y3
G4
x2
E4
x1
comp1bit
U2
E3
y1
G2
G3
comp1bit
U3
Ein=1
y2
x0
G1
comp1bit
U1
E2
wire [4:0] G;
wire [4:0] E;
assign G[4] = 0;
assign E[4] = 1;
assign gt = G[0];
assign eq = E[0];
assign lt = ~(G[0] | E[0]);
y0
G0
gt
comp1bit
U0
E1
eq
E0
lt
xi
Gin
yi
Gout
comp1bit
Ein
Eout
comp1bit U3(.xi(x[3]) ,.yi(y[3]) ,.Ein(E[4]) ,
.Eout(E[3]) ,.Gin(G[4]) ,.Gout(G[3]) );
x3
Gin=0
y3
G4
x2
E4
x1
comp1bit
U2
E3
y1
G2
G3
comp1bit
U3
Ein=1
y2
x0
G1
comp1bit
U1
E2
y0
G0
gt
comp1bit
U0
E1
eq
E0
xi
Gin
yi
Gout
comp1bit
Ein
Eout
comp1bit U3(.xi(x[3]) ,.yi(y[3]) ,.Ein(E[4]) ,
.Eout(E[3]) ,.Gin(G[4]) ,.Gout(G[3]) );
x3
Gin=0
y3
G4
x2
E4
x1
comp1bit
U2
E3
y1
G2
G3
comp1bit
U3
Ein=1
y2
x0
G1
comp1bit
U1
E2
y0
G0
gt
comp1bit
U0
E1
eq
E0
x3
Gin=0
y3
G4
x2
E4
x1
comp1bit
U2
E3
y1
G2
G3
comp1bit
U3
Ein=1
y2
x0
G1
comp1bit
U1
E2
y0
G0
gt
comp1bit
U0
E1
eq
E0
comp1bit U3(.xi(x[3]) ,.yi(y[3]) ,.Ein(E[4]) ,.Eout(E[3]) ,
.Gin(G[4]) ,.Gout(G[3]) );
comp1bit U2(.xi(x[2]) ,.yi(y[2]) ,.Ein(E[3]) ,.Eout(E[2]) ,
.Gin(G[3]) ,.Gout(G[2]) );
comp1bit U1(.xi(x[1]) ,.yi(y[1]) ,.Ein(E[2]) ,.Eout(E[1]) ,
.Gin(G[2]) ,.Gout(G[1]) );
comp1bit U0(.xi(x[0]) ,.yi(y[0]) ,.Ein(E[1]) ,.Eout(E[0]) ,
.Gin(G[1]) ,.Gout(G[0]) );
endmodule