Advertisement
STANAANDREY

ac lab4 pb5

Oct 25th, 2023
1,631
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module cmp2b (
  2.     input [1:0] a, b,
  3.     output lt, eq, gt
  4. );
  5.     assign lt = (a < b) ? 1'b1 : 1'b0;
  6.     assign eq = (a == b) ? 1'b1 : 1'b0;
  7.     assign gt = (a > b) ? 1'b1 : 1'b0;
  8. endmodule
  9.  
  10. module cmp4b (
  11.     input [3:0] a, b,
  12.     output lt, eq, gt
  13. );
  14.     wire lt1, eq1, gt1;
  15.         wire lt2, eq2, gt2;
  16.    
  17.         cmp2b u1 (.a(a[3:2]), .b(b[3:2]), .lt(lt1), .eq(eq1), .gt(gt1));
  18.         cmp2b u2 (.a(a[1:0]), .b(b[1:0]), .lt(lt2), .eq(eq2), .gt(gt2));
  19.         assign lt = (lt1 | (eq1 & lt2));
  20.         assign eq = (eq1 & eq2);
  21.         assign gt = (gt1 | (eq1 & gt2) | (eq2 & gt2));
  22.  
  23. endmodule
  24.  
  25. module cmp4b_tb;
  26.         reg[3:0] a, b;
  27.         wire lt, eq, gt;
  28.         cmp4b cmp4b_i (
  29.         .a(a),
  30.         .b(b),
  31.         .lt(lt),
  32.         .eq(eq),
  33.         .gt(gt)
  34.         );
  35.     integer i, j;
  36.         initial begin
  37.         $display("a\tb\tlt\teq\tgt");
  38.         $monitor("%d\t%d\t%b\t%b\t%b", a, b, lt, eq, gt);
  39.         for (i = 0; i < 16; i = i + 1) begin
  40.             for (j = 0; j < 16; j = j + 1) begin
  41.                 a = i;
  42.                 b = j;
  43.                 #10;    
  44.             end
  45.         end
  46.         end
  47.  
  48. endmodule
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement