Advertisement
Alex9090

Calc Numerice Lab06

Mar 29th, 2018
637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module fact;
  2.  
  3. task factorial;
  4.     input [3:0] n;
  5.     output [31:0] outfact;
  6.     integer count;
  7.     begin
  8.       outfact = 1;
  9.       for(count =n; count > 0; count= count-1)
  10.       outfact = outfact * count;
  11.       end
  12. endtask
  13.  
  14. initial
  15.   begin: init1
  16.     reg [3:0] n;
  17.     reg [31:0] result;
  18.     n = 4'b0101;
  19.     factorial(n, result);
  20.     $display("n=%d fact=%d", n, result);
  21.   end
  22. endmodule
  23.  
  24.  
  25. ((B or C) and (notA)) or (not(A or B))
  26.  
  27. module XOR(a, b, w1);
  28.  
  29.   input a, b;
  30.   output reg w1;
  31.  
  32.   always @(a or b)
  33.   begin
  34.     w1 = a ^ b;
  35.   end
  36.  
  37. endmodule
  38.  
  39. module AND(c, d, w2);
  40.  
  41.   input c, d;
  42.   output reg w2;
  43.  
  44.   always @(c or d)
  45.   begin
  46.     w2 = c & d;
  47.   end
  48. endmodule
  49.  
  50. module OR(e, f, w3);
  51.  
  52.   input e, f;
  53.   output reg w3;
  54.  
  55.   always @(e or f)
  56.   begin
  57.     w3 = e | f;
  58.   end
  59. endmodule
  60.  
  61. module NOR(h, i, w4);
  62.     input h, i;
  63.     output reg w4;
  64.    
  65.     always @(h or i)
  66.     begin
  67.       w4 = ~(h | i);
  68.     end
  69. endmodule      
  70.    
  71. module something(a, b, c, out);
  72.  
  73.   input a, b, c;
  74.   output out;
  75.   wire w1, w2, w3;
  76.   OR or1(b, c, w1);
  77.   AND and1(w1, ~a, w2);
  78.   NOR nor1(a, b, w3);
  79.   OR or2(w2, w3, out);
  80.  
  81.  
  82. endmodule
  83.  
  84. module Testbench;
  85.   reg a, b, c;
  86.   wire cout;
  87.  
  88.  something p(a, b, c, cout);
  89.  initial
  90.   begin
  91.    a = 0;
  92.     b = 0;
  93.     c = 0;
  94.     #1 $display("S=%b", cout);
  95.    
  96.    a = 1;
  97.     b = 1;
  98.     c = 1;
  99.     #1 $display("S=%b ", cout);
  100.    
  101. end
  102.  endmodule
  103.  
  104.  
  105.  
  106.  
  107. Inmultire 2 numere 3 biti -> rezultat 4 biti
  108.  
  109. module XOR(a, b, w1);
  110.  
  111.   input a, b;
  112.   output reg w1;
  113.  
  114.   always @(a or b)
  115.   begin
  116.     w1 = a ^ b;
  117.   end
  118.  
  119. endmodule
  120.  
  121. module AND(c, d, w2);
  122.  
  123.   input c, d;
  124.   output reg w2;
  125.  
  126.   always @(c or d)
  127.   begin
  128.     w2 = c & d;
  129.   end
  130. endmodule
  131.  
  132. module OR(e, f, w3);
  133.  
  134.   input e, f;
  135.   output reg w3;
  136.  
  137.   always @(e or f)
  138.   begin
  139.     w3 = e | f;
  140.   end
  141. endmodule
  142.  
  143. module NOR(h, i, w4);
  144.     input h, i;
  145.     output reg w4;
  146.    
  147.     always @(h or i)
  148.     begin
  149.       w4 = ~(h | i);
  150.     end
  151. endmodule      
  152.    
  153. module something(a0, a1, b0, b1, c0, c1, c2, c3);
  154.  
  155.   input a0, a1, b0, b1;
  156.   output c0, c1, c2, c3;
  157.   wire w1, w3, w4;
  158.   AND and1(a0, b1, w1);
  159.   AND and2(a0, b0, c0);
  160.   AND and3(a1, b0, w3);
  161.   AND and4(a1, b1, w4);
  162.   XOR xor1(w1, w3, c1);
  163.   AND and5(w1, w3, w5);
  164.   XOR xor2(w5, w4, c2);
  165.   AND And6(w4, w5, c3);
  166.  
  167. endmodule
  168.  
  169. module Testbench;
  170.   reg a, a0, b0, b1;
  171.   wire c0, c1, c2, c3;
  172.  
  173.  something p(a, a0, b0, b1, c0,c1,c2,c3);
  174.  initial
  175.   begin
  176.    a  = 0;
  177.    a0 = 1;
  178.    b0 = 1;
  179.    b1 = 1;
  180.     #1 $display("S=%b, S=%b, S=%b, S=%b", c0, c1, c2, c3);
  181.    
  182.      a  = 1;
  183.    a0 = 1;
  184.    b0 = 1;
  185.    b1 = 1;
  186.     #1 $display("S=%b, S=%b, S=%b, S=%b", c0, c1, c2, c3);
  187.    
  188. end
  189.  endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement