|
| 1 | + |
| 2 | +//---------------------------------------------------------------------------- |
| 3 | +//---------------------------------------------------------------------------- |
| 4 | +//-- The Free IP Project |
| 5 | +//-- Verilog Free-CORDIC Core |
| 6 | +//-- (c) 2000, The Free IP Project and Rohit Sharma ([email protected]) |
| 7 | +//-- |
| 8 | +//-- |
| 9 | +//-- FREE IP GENERAL PUBLIC LICENSE |
| 10 | +//-- TERMS AND CONDITIONS FOR USE, COPYING, DISTRIBUTION, AND MODIFICATION |
| 11 | +//-- |
| 12 | +//-- 1. You may copy and distribute verbatim copies of this core, as long |
| 13 | +//-- as this file, and the other associated files, remain intact and |
| 14 | +//-- unmodified. Modifications are outlined below. |
| 15 | +//-- 2. You may use this core in any way, be it academic, commercial, or |
| 16 | +//-- military. Modified or not. |
| 17 | +//-- 3. Distribution of this core must be free of charge. Charging is |
| 18 | +//-- allowed only for value added services. Value added services |
| 19 | +//-- would include copying fees, modifications, customizations, and |
| 20 | +//-- inclusion in other products. |
| 21 | +//-- 4. If a modified source code is distributed, the original unmodified |
| 22 | +//-- source code must also be included (or a link to the Free IP web |
| 23 | +//-- site). In the modified source code there must be clear |
| 24 | +//-- identification of the modified version. |
| 25 | +//-- 5. Visit the Free IP web site for additional information. |
| 26 | +//-- http://www.free-ip.com |
| 27 | +//-- |
| 28 | +//---------------------------------------------------------------------------- |
| 29 | +//---------------------------------------------------------------------------- |
| 30 | +/********************************Test Case *************** |
| 31 | +`include "header.v" |
| 32 | +`include "cla.v" |
| 33 | +`include "BusMux21.v" |
| 34 | +`include "compl.v" |
| 35 | +
|
| 36 | +module test ; |
| 37 | +
|
| 38 | +
|
| 39 | +reg [`REG_SIZE:0] A, B; |
| 40 | +reg Asgn, AS; |
| 41 | +wire [`REG_SIZE:0] S; |
| 42 | +
|
| 43 | +Adder testit ( S, sgn, Asgn, A, B, AS ) ; |
| 44 | +
|
| 45 | +initial |
| 46 | + begin |
| 47 | + AS <= 0; Asgn <= 0 ; |
| 48 | + A <= 12; B<= 65534 ; |
| 49 | +$stop ; |
| 50 | + $monitor ( "Sum=%d sign=%d ASign=%b A=%d B=%d AS=%d", S, sgn, Asgn, A, B, AS ) ; |
| 51 | + end |
| 52 | +endmodule |
| 53 | +
|
| 54 | +********************************Test Case ***************/ |
| 55 | + |
| 56 | +module Adder (S, sign, Asign, A, B, AS); |
| 57 | + output [`REG_SIZE:0] S; |
| 58 | + output sign; |
| 59 | + input [`REG_SIZE:0] A,B; |
| 60 | + input Asign,AS; |
| 61 | + |
| 62 | + wire [`REG_SIZE:0] Atemp,Btemp,Btemp1,Stemp; |
| 63 | + reg [`REG_SIZE:0] CIN; |
| 64 | + wire Y_1,Y_2,Y_3,Y_4; |
| 65 | + |
| 66 | + assign Y_1 = (~AS) & Asign; |
| 67 | + |
| 68 | + BusMux2_1 MUX_0 (Atemp,A,B,Y_1); // xchange A & B |
| 69 | + BusMux2_1 MUX_1 (Btemp,B,A,Y_1); |
| 70 | + |
| 71 | + assign Y_2 = Asign ^ AS; |
| 72 | + |
| 73 | + integer i; |
| 74 | +always @ (Y_2) |
| 75 | + begin |
| 76 | + for(i=0;i<`REG_SIZE+1;i=i+1) |
| 77 | + CIN[i] <= Y_2; |
| 78 | + end |
| 79 | + assign Btemp1 = Btemp ^ CIN; |
| 80 | + |
| 81 | + CLA Add1 (Stemp[`CLA_SIZE:0],W_1,Atemp[`CLA_SIZE:0],Btemp1[`CLA_SIZE:0],Y_2); |
| 82 | + |
| 83 | + CLA Add2 (Stemp[((`CLA_SIZE + 1)*2 - 1):(`CLA_SIZE + 1)],W_2,Atemp[((`CLA_SIZE + 1)*2 - 1):(`CLA_SIZE + 1)],Btemp1[((`CLA_SIZE + 1)*2 - 1):(`CLA_SIZE + 1)],W_1); |
| 84 | + |
| 85 | + CLA Add3 (Stemp[((`CLA_SIZE + 1)*3 - 1):((`CLA_SIZE + 1)*2)],W_3,Atemp[((`CLA_SIZE + 1)*3 - 1):((`CLA_SIZE + 1)*2)],Btemp1[((`CLA_SIZE + 1)*3 - 1):((`CLA_SIZE + 1)*2)],W_2); |
| 86 | + |
| 87 | + CLA Add4 (Stemp[`REG_SIZE:(`CLA_SIZE + 1)*3],Y_3,Atemp[`REG_SIZE:(`CLA_SIZE + 1)*3],Btemp1[`REG_SIZE:(`CLA_SIZE + 1)*3],W_3); |
| 88 | + |
| 89 | + assign Y_4 = (~Y_3) & (Asign ^ AS); |
| 90 | + |
| 91 | + complement Compl (S,Stemp,Y_4); // 2's Complement if result neg. |
| 92 | + assign sign = (~Y_3 & AS) | (~Y_3 & Asign) | (AS & Asign); |
| 93 | + |
| 94 | +endmodule // Adder |
0 commit comments