Advertisement
kekellner

Lab08 - Ej02

Oct 15th, 2021
2,315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `include "full_adder.v"
  2.  
  3. module rca (input [3:0] A, B, input Cin, output [3:0] S, output Cout);
  4.  
  5.     wire FA1_to_FA2, FA2_to_FA3, FA3_to_FA4;
  6.  
  7.     full_adder U1(A[0], B[0], Cin, S[0], FA1_to_FA2);
  8.     full_adder U2(.A(A[1]), .B(B[1]), .Cin(FA1_to_FA2), .S(S[1]), .Cout(FA2_to_FA3)); // Otra forma de hacer las interconexiones
  9.     full_adder U3(.S(S[2]), .Cout(FA3_to_FA4), .Cin(FA2_to_FA3), .B(B[2]), .A(A[2]));
  10.     full_adder U4(A[3], B[3], FA3_to_FA4, S[3], Cout);
  11.  
  12.  
  13. endmodule
  14.  
  15. module testbench();
  16.  
  17.     reg [3:0] A, B;
  18.     reg Cin;
  19.     wire [3:0] S;
  20.     wire Cout;
  21.  
  22.     rca U1(A, B, Cin, S, Cout);
  23.  
  24.     initial begin
  25.         $display("Cin\tA\tB    |\tS\tCout");
  26.         $display("------------------------------------");
  27.         $monitor("%b\t%b\t%b |\t%b\t%b", Cin, A, B, S, Cout);
  28.         A = 0; B = 0; Cin = 0;
  29.         #1
  30.         A = 1; B = 1; Cin = 0;
  31.         #1
  32.         Cin = 1; A = 1; B = 1;
  33.         #1
  34.         Cin = 0; A = 15; B = 1;
  35.         #1
  36.         Cin = 0; A = 15; B = 2;
  37.         #1
  38.         Cin = 1; A = 15; B = 1;
  39.         #1
  40.         Cin = 1; A = 4; B = 4;
  41.         #1
  42.         Cin = 0; A = 1; B = 15;
  43.         #1
  44.         Cin = 1; A = 1; B = 15;
  45.         #1
  46.         Cin = 1; A = 5; B = 7;
  47.     end
  48.  
  49. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement