Advertisement
Guest User

VLSI_L3

a guest
Mar 17th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //L3_Ex1
  2. module ex1(out,A,B,SEL);
  3.     input A,B,SEL;
  4.     output out;
  5.     wire w1,w2,w3;
  6.     not gate_NU(w1,SEL);
  7.     and gate1_SI(w2,w1,A);
  8.     and gate2_SI(w3,SEL,B);
  9.     or gate_SAU(out,w2,w3);
  10. endmodule
  11.  
  12. module test_ex1();
  13.     reg A,B,SEL;
  14.     wire out;
  15.     initial begin
  16.         A=0;B=0;SEL=0;
  17.         #50 B=1;
  18.         #50 A=1;B=0;SEL=1;
  19.         #50 B=1;
  20.     #50 B=1;
  21.     end
  22.     ex1 test1(out,A,B,SEL);
  23. endmodule
  24. //L2_Ex1_B
  25. module ex1_B(out,A,B,SEL);
  26.     input A,B,SEL;
  27.     output out;
  28.     //assign out = (~SEL&A)|(SEL&B);
  29.     //op conditional cond ? exp1:exp2;
  30.     assign out = SEL? B : A;
  31. endmodule
  32. module test_ex1_B();
  33.     reg A,B,SEL;
  34.     wire out;
  35.     initial begin
  36.         A=0;B=0;SEL=0;
  37.         #50 B=1;
  38.         #50 A=1;B=0;SEL=1;
  39.         #50 B=1;
  40.     #50 SEL=0;
  41.     end
  42.     ex1_B test1(out,A,B,SEL);
  43. endmodule
  44.  
  45.  
  46.  
  47. //---------
  48.  
  49. module test_ex2();
  50.     reg A,B,Cin;
  51.     wire out,cout;
  52.     initial begin
  53.         A=0;B=0;Cin=0;
  54.         #50 B=1;
  55.         #50 A=1;
  56.         #50 Cin=1;
  57.     #50 A=1;
  58.     end
  59.     sum1b test1(cout,out,A,B,Cin);
  60. endmodule
  61. //sum4bit
  62. module ex2_B(Cout,S,A,B,Cin);
  63.     input [3:0]A,B;
  64.     input Cin;
  65.     output Cout;
  66.     output [3:0]S;
  67.     wire w1,w2,w3;
  68.     sum1b s1(w1,S[0],A[0],B[0],Cin);
  69.     sum1b s2(w2,S[1],A[1],B[1],Cin);
  70.     sum1b s3(w3,S[2],A[2],B[2],Cin);
  71.     sum1b s4(Cout,S[3],A[3],B[3],Cin);
  72. endmodule
  73. module sum1b(Cout,out,A,B,Cin);
  74.     input A,B,Cin;
  75.     output Cout,out;
  76.     assign {Cout,out} = A+B+Cin;
  77. endmodule
  78. module test_ex2_B();
  79.     reg [3:0]A,B;
  80.     reg Cin;
  81.     wire [3:0]out;
  82.     wire cout;
  83.     initial begin
  84.         A=10;B=6;Cin=0;
  85.         #50 B=1;
  86.         #50 A=1;
  87.         #50 Cin=1;
  88.     #50 A=1;
  89.     end
  90.     ex2_B test2b(cout,out,A,B,Cin);
  91. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement