Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module accumulator_N_bits
  2.     #(N=8)
  3.     (input [N-1:0] A,
  4.     input clk,
  5.     output [N-1:0] S,
  6.     output overflow, carry);
  7.    
  8.     (* keep *) wire [N-1:0] B,C;
  9.     (* keep *) wire cout,over;
  10.    
  11.     register_N_bits #(8) ex_A(A,clk,B);
  12.    
  13.     adder_N_bits #(8) ex_add(B,S,1'b0,C,cout);
  14.    
  15.     register_N_bits #(8) ex_S(C,clk,S);
  16.     FFD_posedge ex_cout(cout,clk,carry);
  17.     assign over = cout ^ C[N-1];
  18.     FFD_posedge ex_over(over,clk,overflow);
  19. endmodule
  20.  
  21. module adder_N_bits
  22.     #(parameter N=4)
  23.     (input [N-1:0] A, B, input CI,
  24.     output [N-1:0] S, output CO);
  25.     wire [N-1:0] c;
  26.     generate
  27.         genvar i;
  28.         for (i=0; i<N; i=i+1)
  29.         begin: ad
  30.                 case(i)
  31.                     0:  adder_1_bits x(A[i], B[i], CI, S[i], c[i]);
  32.                     N-1:    adder_1_bits x(A[i], B[i], c[i-1], S[i], CO);
  33.                     default:    adder_1_bits x(A[i], B[i], c[i-1], S[i], c[i]);
  34.                 endcase
  35.         end
  36.     endgenerate
  37. endmodule
  38.  
  39. module FFD_posedge(
  40.     input D,clk,
  41.     output reg Q);
  42.    
  43.     always @(posedge clk)
  44.         Q <= D;
  45. endmodule
  46.  
  47. module register_N_bits
  48.     #(N=8)
  49.     (input [N-1:0] D,
  50.     input clk,
  51.     output reg [N-1:0] Q);
  52.    
  53.     always @(posedge clk)
  54.         Q <= D;
  55. endmodule
  56.  
  57. module adder_1_bits(
  58.     input a,b,cin,
  59.     output s,cout);
  60.    
  61.     assign s = a ^ b ^ cin;
  62.     assign cout = a & b & (a ^ b) & cin;
  63. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement