Advertisement
lope3x

Somado Completo

Oct 27th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // -------------------------
  2. // Somador Completo para um bit
  3. // Output carryOut("vai um")
  4. // Output soma(resultado da soma)
  5. // inputs a,b,CarryIn("Vem um")
  6. // -------------------------
  7. module fullAdder ( output carryOut,output soma,input a,input b,input carryIn );
  8. wire nota;
  9. wire notb;
  10. wire notcarryIn;
  11. wire and1;
  12. wire and2;
  13. wire and3;
  14. wire and4;
  15. wire and5;
  16. wire and6;
  17. wire and7;
  18. wire and8;
  19. not notA(nota,a);
  20. not notB(notb,b);
  21. not notcarry(notcarryIn,carryIn);
  22. and and1(and1,nota,notb,carryIn);
  23. and and2(and2,nota,b,notcarryIn);
  24. and and3(and3,a,notb,notcarryIn);
  25. and and4(and4,a,b,carryIn);
  26. or or1(soma,and1,and2,and3,and4);
  27. and and5(and5,nota,b,carryIn);
  28. and and6(and6,a,notb,notcarryIn);
  29. and and7(and7,a,b,notcarryIn);
  30. and and8(and8,a,b,carryIn);
  31. or or2(carryOut,a,b,carryIn);
  32. endmodule // fullAdder
  33. module test_fullAdder;
  34. // ------------------------- definir dados
  35. reg [3:0] a;
  36. reg [3:0] b;
  37. wire [3:0] carryOut; // “vai-um”
  38. wire [4:0] soma;
  39. fullAdder FA0 ( carryOut[0], soma[0], a[0], b[0],1'b0);
  40. fullAdder FA1 ( carryOut[1], soma[1], a[1], b[1],carryOut[0]);
  41. fullAdder FA2 ( carryOut[2], soma[2], a[2], b[2],carryOut[1]);
  42. fullAdder FA3 ( carryOut[3], soma[3], a[3], b[3],carryOut[2]);
  43. assign soma[4]=carryOut[3];
  44. // ------------------------- parte principal
  45. initial begin
  46. $display("   a    b  soma  vai(carry)");
  47. $monitor("%4b %4b %4b %4b", a, b, soma, carryOut);
  48. a = 4'b0000; b = 4'b0000;
  49. #1 a = 4'b0001; b = 4'b0001;
  50. #1 a = 4'b0010; b = 4'b0010;
  51. #1 a = 4'b0011; b = 4'b0011;
  52. end
  53. endmodule // test_fullAdder
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement