Advertisement
voltairenism

CeciliaCamimura_Somador4bits_Iverilog

Jun 20th, 2021
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. /* Somador completo de 1-bit */
  2. module somador_1_bit(y,co,a,b,ci);
  3. output y,co;
  4. input a,b,ci;
  5. wire y,co,a,b,ci;
  6.  
  7. assign y = (a^b)^ci;
  8. assign co = (a&b)|(a&ci)|(b&ci);
  9. endmodule
  10.  
  11. /*Somador de 4-bit */
  12.  
  13. module somador_4_bits(y,c,a,b);
  14. output [3:0]y;
  15. output c;
  16. input [3:0]a;
  17. input [3:0]b;
  18. wire [3:0]y;
  19. wire c,c1,c2,c3;
  20. wire [3:0]a;
  21. wire [3:0]b;
  22.  
  23. somador_1_bit s1(y[0],c1,a[0],b[0],c);
  24. somador_1_bit s2(y[1],c2,a[1],b[1],c1);
  25. somador_1_bit s3(y[2],c3,a[2],b[2],c2);
  26. somador_1_bit s4(y[3],c,a[3],b[3],c3);
  27.  
  28. endmodule
  29.  
  30. /* Complemento de 2 1-bit */
  31. module comp_2(y,sco,a,sub,sci);
  32. output y,sco;
  33. input a,sub,sci;
  34. wire y,sco,a,sub,sci,x;
  35.  
  36. assign x = a^sub;
  37. assign y = x^sci;
  38. assign sco = x&sci;
  39.  
  40. endmodule
  41.  
  42. /* Test-bench do somador de 1-bit */
  43. module tb();
  44.  
  45. reg [3:0]a;
  46. reg [3:0]b; // entradas de controle comuns e D do flip-flop
  47. wire [3:0]y;
  48. wire c; // saídas
  49.  
  50. initial begin
  51. $dumpfile("somador.vcd");
  52. $dumpvars(0,tb);
  53.  
  54. /* Initial values */
  55. a = 4'b0000;
  56. b = 4'b0000;
  57.  
  58. #10 a = 4'b0001;
  59. #10 b = 4'b0001;
  60. #10 a = 4'b1000;
  61. #10 b = 4'b0010;
  62. #10 b = 4'b0011; a = 4'b0100;
  63. #10 b = 4'b1111; a = 4'b1111;
  64. #10 $finish;
  65. end
  66.  
  67. somador_4_bits s(y,c,a,b);
  68.  
  69. endmodule
  70.  
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement