Advertisement
Andrei_M

BCD tetrad adder using FAC

Nov 19th, 2019
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module fac(
  2.   input x, y, ci,
  3.   output z, co
  4.   );
  5.   assign {co, z} = x + y +ci;
  6. endmodule
  7.  
  8. module bcd_add(
  9.   input [3:0] x, y,
  10.   input ci,
  11.   output [3:0] z,
  12.   output co
  13.   );
  14.  
  15.   wire c1,c2,c3,c4,z1p,z2p,z3p,c2p,c3p;
  16.   //de pe desen
  17.   fac u0(
  18.   .x(x[0]),
  19.   .y(y[0]),
  20.   .ci(ci),
  21.   .z(z[0]),
  22.   .co(c1)
  23.   );
  24.  
  25.   fac u1(
  26.   .x(x[1]),
  27.   .y(y[1]),
  28.   .ci(c1),
  29.   .z(z1p),
  30.   .co(c2)
  31.   );
  32.  
  33.   fac u2(
  34.   .x(x[2]),
  35.   .y(y[2]),
  36.   .ci(c2),
  37.   .z(z2p),
  38.   .co(c3)
  39.   );
  40.  
  41.   fac u3(
  42.   .x(x[3]),
  43.   .y(y[3]),
  44.   .ci(c3),
  45.   .z(z3p),
  46.   .co(c4)
  47.   );
  48.  
  49.   assign co = (z1p & z2p) | (z2p & z3p) | c4;
  50.  
  51.   fac u4(
  52.   .x(co),
  53.   .y(z1p),
  54.   .ci(1'b0),
  55.   .z(z[1]),
  56.   .co(c2p)
  57.   );
  58.  
  59.   fac u5(
  60.   .x(co),
  61.   .y(z2p),
  62.   .ci(c2p),
  63.   .z(z[2]),
  64.   .co(c3p)
  65.   );
  66.  
  67.   assign z[3] = z3p ^ c3p;
  68.  
  69. endmodule
  70.  
  71.  
  72.  
  73. //-----------------------------------------------------------------------------
  74.  
  75.  
  76. module bcd_add_tb
  77.   (
  78.   output reg [3:0] x, y,
  79.   output reg ci,
  80.   output [3:0] z,
  81.   output co
  82.   );
  83.  
  84.   bcd_add test(
  85.   .x(x),
  86.   .y(y),
  87.   .ci(ci),
  88.   .z(z),
  89.   .co(co)
  90.   );
  91.  
  92.   integer i, j, k;
  93.   initial begin
  94.     {x,y,ci} = 9'd0;
  95.     for(i = 0; i < 10; i = i+1)
  96.       for(j = 0; j < 10; j = j+1)
  97.         for(k = 0; k < 2; k = k+1)
  98.       #100 {x,y,ci} = {i[3:0], j[3:0], k[0]};
  99.     end
  100.   endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement