Advertisement
icatalin

LAB3 CN 07.03.2019

Mar 7th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. hello_world.v////////////////////////////////////////////////////////////////////////////////////////////////
  2.  
  3. module hello_world;
  4.  
  5. initial begin
  6.     $display ("Hello_world!");
  7.     #10 $finish;
  8. end
  9.  
  10. endmodule
  11.  
  12.  
  13. and_from_nand_gates.v////////////////////////////////////////////////////////////////////////////////////////////////
  14. module NAND (in1, in2, out);
  15.  
  16. input in1, in2;
  17. output out;
  18.  
  19. assign out= ~(in1 & in2);
  20.  
  21. endmodule
  22.  
  23. module AND (in1, in2, out);
  24.  
  25. input in1, in2;
  26. output out;
  27. wire w1;
  28.  
  29. NAND NAND1 (in1, in2, w1);
  30. NAND NAND2 (w1, w1, out);
  31.  
  32. endmodule
  33.  
  34. module Testbench;
  35. reg a, b;
  36. wire out1, out2;
  37.  
  38. initial begin
  39.  
  40. a=0; b=0;
  41. #1 a=1;
  42. #1 b=1;
  43. #1 a=0;
  44.  
  45. end
  46.  
  47. initial begin
  48. $monitor ("Time=%0d a=%b out1=%b out2=%b", $time, a,b, out1, out2);
  49. end
  50.  
  51. //instantele modulelor AND si NAND
  52. AND and_gate(a, b, out1);
  53. NAND nand_gate(a, b, out2);
  54.  
  55. endmodule
  56.  
  57.  
  58.  
  59.  
  60. 4bit_adder.v////////////////////////////////////////////////////////////////////////////////////////////////
  61.  
  62. `timescale 1ns / 1ps
  63.  
  64. module Adder(A, B, Result);
  65.  
  66.     input [3:0] A;
  67.     input [3:0] B;
  68.     output [3:0] Result;
  69.     reg [3:0] Result;
  70.  
  71.     always @ (A or B)
  72.     begin
  73.  
  74.         Result <= A + B;
  75.     end
  76.  
  77. endmodule
  78.  
  79. module Testbench;
  80.  
  81.     reg [3:0] A_t;
  82.     reg [3:0] B_t;
  83.     wire [3:0] Result_t;
  84.  
  85.     Adder Adder_1(A_t, B_t, Result_t);
  86.  
  87.     initial
  88.     begin
  89.  
  90.         //case 0
  91.         A_t <= 0; B_t <= 0;
  92.         #1 $display("Result_t = %b", Result_t);
  93.  
  94.         //case 1
  95.         A_t <= 6; B_t <= 1;
  96.         #1 $display("Result_t = %b", Result_t);
  97.  
  98.         //case 2
  99.         A_t <= 1; B_t <= 0;
  100.         #1 $display("Result_t = %b", Result_t);
  101.  
  102.         //case 3 (overflow should occur)
  103.         A_t <= 10; B_t <= 10;
  104.         #1 $display("Result_t = %b", Result_t);
  105.  
  106.     end
  107. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement