Download
verilog code for 8 bit comparator n.
Skip this Video
Loading SlideShow in 5 Seconds..
Verilog Code for 8-bit Comparator PowerPoint Presentation
Download Presentation
Verilog Code for 8-bit Comparator

Verilog Code for 8-bit Comparator

2218 Views Download Presentation
Download Presentation

Verilog Code for 8-bit Comparator

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Verilog Code for 8-bit Comparator Dept. of CSIE Fu Jen Catholic University

  2. 1-bit Comparator – Dataflow moduleOneBitComparator_D(x, y, G, L, E); input x, y; output G, L, E; assign G = x & ~y; ………… endmodule

  3. 2-bit Comparator – Behavioral (1) moduleTwoBitComparator_B(X, Y, G, L, E); input[1:0] X, Y; output regG, L, E; always @(X, Y) // (X or Y) is OK, too begin G = (X > Y) ? 1 : 0; // try if G = (X > Y); is also OK. ……….. // try if L = (X < Y); is also OK. E = (X == Y); // E = ~(G | L); end endmodule

  4. 2-bit Comparator – Behavioral (2) moduleTwoBitComparator_B(X, Y, G, L, E); input[1:0] X, Y; output regG, L, E; always @(X, Y) // (X or Y) is OK, too begin G = 0; L = 0; E = 0; if (X > Y) G = 1; else if (X < Y) L = 1; else E = 1; end endmodule

  5. CompareMerge - Dataflow moduleCompareMerge(g1, g0, l1, l0, e1, e0, G, L, E); input g1, g0, l1, l0, e1, e0; output G, L, E; assign G = g1 | ( e1 & g0 ); …………. endmodule

  6. 4-bit Comparator - Structural module FourBitComparator_S(X , Y, G, L, E); input[3:0] X, Y; output G, L, E; wire g1, l1, e1, g0, l0, e0; TwoBitComparator_B high (X[3:2], Y[3:2], g1, l1, e1); ………….. // TwoBitComparator_B low CompareMerge merge(g1, g0, l1, l0, e1, e0, G, L, E); endmodule

  7. 8-bit Comparator - Structural moduleEightBitComparator_S(X , Y, G, L, E); input[7:0] X, Y; output G, L, E; wire g1, l1, e1, g0, l0, e0; ………………… // reference 4-bit Comparator Structural endmodule

  8. Top Module of 8-Bit Comparator module Top_8BitCompartor(HEX7, HEX6, HEX5, HEX4, HEX3, SW, LEDR); input[15:0] SW; output[15:0] LEDR; output[6:0] HEX7, HEX6, HEX5, HEX4, HEX3; wire [7:0] X, Y; assign X = SW[15:8]; assign Y = SW[7:0]; assign LEDR[15:0] = SW[15:0]; seg7 x_high(X[7:4], HEX7); // X’s high nibble: X[7:4] and it is shown HEX7 …………..// X’s low nibble: X[3:0] and it is shown HEX6 // Y’shigh nibble: Y[7:4] and it is shown in HEX5 // Y’s low nibble: Y[3:0] and it is shown in HEX4 seg7_cmp display(………..); // {G, L, E} show in HEX3 EightBitComparator_SC8(X, Y, G, L, E); endmodule