Advertisement
Guest User

Untitled

a guest
Jun 24th, 2024
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module RIPPLECARRY(
  2.    
  3.     output wire Carry,
  4.     output wire [7:0] Sum,
  5.     input wire [7:0] A, B,
  6.     input wire Cin
  7.    
  8.     );
  9.  
  10.     wire C0, C1, C2, C3, C4, C5, C6;
  11.  
  12.     FULLADDER FA0 (C0, Sum[0], A[0], B[0], Cin);
  13.     FULLADDER FA1 (C1, Sum[1], A[1], B[1], C0);
  14.     FULLADDER FA2 (C2, Sum[2], A[2], B[2], C1);
  15.     FULLADDER FA3 (C3, Sum[3], A[3], B[3], C2);
  16.     FULLADDER FA4 (C4, Sum[4], A[4], B[4], C3);
  17.     FULLADDER FA5 (C5, Sum[5], A[5], B[5], C4);
  18.     FULLADDER FA6 (C6, Sum[6], A[6], B[6], C5);
  19.     FULLADDER FA7 (Carry, Sum[7], A[7], B[7], C6);
  20.  
  21. endmodule
  22.  
  23.  
  24. module MUX2_1(
  25.    
  26.     output wire [7:0] F,
  27.     input wire S,
  28.     input wire [7:0] A, B
  29.    
  30.     );
  31.  
  32.     wire nS;
  33.     wire [7:0] wA, wB;
  34.  
  35.     NOT NOT0 (nS, S);
  36.  
  37.     AND AND0 (wA[0], A[0], nS);
  38.     AND AND1 (wA[1], A[1], nS);
  39.     AND AND2 (wA[2], A[2], nS);
  40.     AND AND3 (wA[3], A[3], nS);
  41.     AND AND4 (wA[4], A[4], nS);
  42.     AND AND5 (wA[5], A[5], nS);
  43.     AND AND6 (wA[6], A[6], nS);
  44.     AND AND7 (wA[7], A[7], nS);
  45.  
  46.     AND AND8 (wB[0], B[0], S);
  47.     AND AND9 (wB[1], B[1], S);
  48.     AND AND10 (wB[2], B[2], S);
  49.     AND AND11 (wB[3], B[3], S);
  50.     AND AND12 (wB[4], B[4], S);
  51.     AND AND13 (wB[5], B[5], S);
  52.     AND AND14 (wB[6], B[6], S);
  53.     AND AND15 (wB[7], B[7], S);
  54.  
  55.     OR8 OR0 (F, wA, wB);
  56.  
  57. endmodule
  58.  
  59. module dflipflop (output reg Q,Qn,
  60.                   input wire clk, res, EN, D);
  61.  
  62.   always @ (posedge clk or negedge res or negedge EN)
  63.     begin
  64.         if (!res)
  65.             begin
  66.                 Q <= 1'b0;
  67.                 Qn <= 1'b1;
  68.             end
  69.         else if (!EN)
  70.             begin
  71.                 Q <= 1'b1;
  72.                 Qn <= 1'b0;
  73.             end
  74.         else
  75.             begin
  76.                 Q <= D;
  77.                 Qn <= ~D;
  78.             end
  79.     end
  80.  
  81. endmodule
  82.  
  83. /*-----------------------------------------------REGISTERS-----------------------------------------------*/
  84.  
  85. module reg8a (
  86.        
  87.     output wire [7:0] Reg_Out,
  88.     input wire clk, res, EN,
  89.     input wire [7:0] Reg_In
  90.    
  91.     );
  92.  
  93.     wire [7:0] nQ;
  94.     wire [7:0] Mux_Out;
  95.  
  96.     MUX2_1 mux0 (Mux_Out, EN, Reg_Out, Reg_In);
  97.  
  98.     dflipflop dff0 (Reg_Out[0], nQ[1], clk, res, 1'b1, Mux_Out[0]);
  99.     dflipflop dff1 (Reg_Out[1], nQ[0], clk, res, 1'b1, Mux_Out[1]);
  100.     dflipflop dff2 (Reg_Out[2], nQ[3], clk, res, 1'b1, Mux_Out[2]);
  101.     dflipflop dff3 (Reg_Out[3], nQ[2], clk, res, 1'b1, Mux_Out[3]);
  102.     dflipflop dff4 (Reg_Out[4], nQ[5], clk, res, 1'b1, Mux_Out[4]);
  103.     dflipflop dff5 (Reg_Out[5], nQ[4], clk, res, 1'b1, Mux_Out[5]);
  104.     dflipflop dff6 (Reg_Out[6], nQ[7], clk, res, 1'b1, Mux_Out[6]);
  105.     dflipflop dff7 (Reg_Out[7], nQ[6], clk, res, 1'b1, Mux_Out[7]);
  106.  
  107. endmodule
  108.  
  109. /*-----------------------------------------------COUNTER-----------------------------------------------*/
  110.  
  111. module count8a (
  112.    
  113.     output wire [7:0] CNT,
  114.     input wire clk, res, EN, load,
  115.     input wire [7:0] CNT_In
  116.    
  117.     );
  118.    
  119.     wire Cout;
  120.     wire [7:0] Mux_Out;
  121.     wire [7:0] Inc_Out;
  122.  
  123.     MUX2_1 mux0 (Mux_Out, load, Inc_Out, CNT_In);
  124.  
  125.     RIPPLECARRY adder0 (Cout, Inc_Out, CNT, 8'b00000001, 1'b0);
  126.  
  127.     reg8a reg0 (CNT, clk, res, EN, Mux_Out);
  128.  
  129. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement