Advertisement
Guest User

16 bit carry look ahead

a guest
Sep 15th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. timescale 1ns / 1ps
  2.  
  3. module Partial_Add(output P,G,S,
  4. input A,B,Ci );
  5. //Gate modeling of Partial adder
  6. xor Prop(P,A,B);
  7. xor Sum(S,A,B,Ci);
  8. and Gen(G,A,B);
  9.  
  10. endmodule
  11.  
  12. module Carry_look(output Pg,Gg,
  13. output [3:0] Cout ,
  14. input [3:0] P,G,
  15. input Ci);
  16.  
  17. wire P0Ci;
  18. and(P0Ci,P[0],Ci);
  19. or (Cout[0],G[0],P0Ci);
  20.  
  21. wire P1G0;
  22. wire P1P0;
  23. and (P1G0,P[1],G[0]);
  24. and (P1P0Ci,P[1],P[0],Ci);
  25. or (Cout[1],G[1],P1G0,P1P0Ci);
  26.  
  27. wire P2G1;
  28. wire P2P2G0;
  29. wire P2P1P0;
  30. and (P2G1,P[2],G[1]);
  31. and (P2P1G0,P[2],P[1],G[0]);
  32. and (P2P1P0Ci,P[2],P[1],P[0],Ci);
  33. or (Cout[2],G[2],P2G1,P2P1G0,P2P1P0Ci);
  34.  
  35. wire P3G2;
  36. wire P3P2G1;
  37. wire P3P2P1G0;
  38. wire P3P2P1;
  39. and (P3G2,P[3],G[2]);
  40. and (P3P2G1,P[3],P[2],G[1]);
  41. and (P3P2P1G0,P[3],P[2],P[1],G[0]);
  42. and (P3P2P1Ci,P[3],P[2],P[1],Ci);
  43. or (Cout[3],G[3],P3G2,P3P2G1,P3P2P1G0,P3P2P1Ci);
  44.  
  45. or (Gg,G[3],P3G2,P3P2G1,P3P2P1G0);
  46. and(Pg,P);
  47.  
  48. endmodule
  49.  
  50. module Carry_look_4bit(output Co,
  51. output [3:0] S,
  52. output Pg,Gg,
  53. input [3:0] A,B,
  54. input Ci);
  55. wire [3:0] Car;
  56. wire [3:0] P,G;
  57.  
  58. //This will put all the Partial adders and the CLA together
  59. Partial_Add add[3:0](.P(P),.G(G),.S(S),.A(A),.B(B),.Ci(Car)); //P takes P as input etc
  60. Carry_look CLA1(.Pg(Pg),.Gg(Gg),.Cout(Car),.P(P),.G(G),.Ci(Ci)); //Pu takes Pu as input etc
  61.  
  62.  
  63. assign Co=Car[3]; //Co will be Carry 3
  64. endmodule
  65.  
  66. module LookAhead_16b(output Co,
  67. output [15:0] S,
  68. input [15:0] A,B,
  69. input Ci);
  70. wire [3:0] Car;
  71. wire [3:0] P;
  72. wire [3:0] G;
  73. wire Pg;
  74. wire Gg;
  75. wire C1;
  76. wire C2;
  77. wire C3;
  78. wire C4;
  79. //These are the 4, 4 bit Carry looks with their respected inputs and lines defined
  80. Carry_look_4bit A1 (.Co(C1),.S(S[3:0]),.Pg(P[0]),.Gg(G[0]),.A(A[3:0]),.B(B[3:0]),.Ci(Ci));
  81. Carry_look_4bit A2 (.Co(C2),.S(S[7:4]),.Pg(P[1]),.Gg(G[1]),.A(A[7:4]),.B(B[7:4]),.Ci(Car[0]));
  82. Carry_look_4bit A3 (.Co(C3),.S(S[11:8]),.Pg(P[2]),.Gg(G[2]),.A(A[11:8]),.B(B[11:8]),.Ci(Car[1]));
  83. Carry_look_4bit A4 (.Co(C4),.S(S[15:12]),.Pg(P[3]),.Gg(G[3]),.A(A[15:12]),.B(B[15:12]),.Ci(Car[2]));
  84.  
  85. Carry_look CLA2(.Pg(Pg),.Gg(Gg),.Cout(Car),.P(P),.G(G),.Ci(Ci));
  86. //This makes the carry out, the last carry of the last CLA
  87.  
  88.  
  89. assign Co = Car[3];
  90.  
  91. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement