Holey_yan

20141002_KUAS_Verilog_FullAdder_8Bit(GateLevel)

Oct 17th, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /************************************************/
  2. /** 20141002 8-Bit Full Adder (Use Gate Level) **/
  3. /** Maker  : Yan                               **/
  4. /** E-Mail : [email protected]             **/
  5. /** Date   : 2014/10/02 pm.10:30               **/
  6. /************************************************/
  7.  
  8. module FullAdder_8Bit(input1, input2, carryIn, sum, carryOut);
  9.     input       [7:0]   input1, input2; input   carryIn;
  10.     output      [7:0]   sum;        output  carryOut;
  11.     wire        [6:0]   _wire;
  12.    
  13.     FullAdder   tmp1(.input1(input1[0]), .input2(input2[0]), .carryIn(carryIn), .sum(sum[0]), .carryOut(_wire[0]));
  14.     FullAdder   tmp2(.input1(input1[1]), .input2(input2[1]), .carryIn(_wire[0]), .sum(sum[1]), .carryOut(_wire[1]));
  15.     FullAdder   tmp3(.input1(input1[2]), .input2(input2[2]), .carryIn(_wire[1]), .sum(sum[2]), .carryOut(_wire[2]));
  16.     FullAdder   tmp4(.input1(input1[3]), .input2(input2[3]), .carryIn(_wire[2]), .sum(sum[3]), .carryOut(_wire[3]));
  17.     FullAdder   tmp5(.input1(input1[4]), .input2(input2[4]), .carryIn(_wire[3]), .sum(sum[4]), .carryOut(_wire[4]));
  18.     FullAdder   tmp6(.input1(input1[5]), .input2(input2[5]), .carryIn(_wire[4]), .sum(sum[5]), .carryOut(_wire[5]));
  19.     FullAdder   tmp7(.input1(input1[6]), .input2(input2[6]), .carryIn(_wire[5]), .sum(sum[6]), .carryOut(_wire[6]));
  20.     FullAdder   tmp8(.input1(input1[7]), .input2(input2[7]), .carryIn(_wire[6]), .sum(sum[7]), .carryOut(carryOut));
  21. endmodule
  22.  
  23. module FullAdder(input1, input2, carryIn, sum, carryOut);
  24.     input       input1, input2, carryIn;
  25.     output      sum, carryOut;
  26.     wire        w1, w2, w3;
  27.    
  28.     HalfAdder   tmp1(.input1(input1), .input2(input2), .sum(w1), .carryOut(w2));
  29.     HalfAdder   tmp2(.input1(w1), .input2(carryIn), .sum(sum), .carryOut(w3));
  30.    
  31.     or      (carryOut, w2, w3);
  32. endmodule
  33.  
  34. module HalfAdder(input1, input2, sum, carryOut);
  35.     input       input1, input2;
  36.     output      sum, carryOut;
  37.    
  38.     xor     (sum, input1, input2);
  39.     and     (carryOut, input1, input2);
  40. endmodule
Advertisement
Add Comment
Please, Sign In to add comment