Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. module yMux1(z, a, b, c);
  2. output z;
  3. input a, b, c;
  4. wire notC, upper, lower;
  5. not my_not(notC, c);
  6. and upperAnd(upper, a, notC);
  7. and lowerAnd(lower, c, b);
  8. or my_or(z, upper, lower);
  9. endmodulemodule yMux(z, a, b, c);
  10. parameter SIZE = 2;
  11. output [SIZE-1:0] z;
  12. input [SIZE-1:0] a, b;
  13. input c;
  14. yMux1 mine[SIZE-1:0](z, a, b, c);
  15. endmodulemodule yMux4to1(z, a0,a1,a2,a3, c);
  16. parameter SIZE = 2;
  17. output [SIZE-1:0] z;
  18. input [SIZE-1:0] a0, a1, a2, a3;
  19. input [1:0] c;
  20. wire [SIZE-1:0] zLo, zHi;
  21. yMux #(SIZE) lo(zLo, a0, a1, c[0]);
  22. yMux #(SIZE) hi(zHi, a2, a3, c[0]);
  23. yMux #(SIZE) final(z, zLo, zHi, c[1]);
  24. endmodulemodule yAdder1(z, cout, a, b, cin);
  25. output z, cout;
  26. input a, b, cin;
  27. xor left_xor(tmp, a, b);
  28. xor right_xor(z, cin, tmp);
  29. and left_and(outL, a, b);
  30. and right_and(outR, tmp, cin);
  31. or my_or(cout, outR, outL);
  32. endmodulemodule yAdder(z, cout, a, b, cin);
  33. output [31:0] z;
  34. output cout;
  35. input [31:0] a, b;
  36. input cin;
  37. wire[31:0] in, out;
  38. yAdder1 mine[31:0](z, out, a, b, in);
  39. assign {cout,in} = {out,cin};
  40. endmodulemodule yArith (z, cout, a, b, ctrl) ;
  41. // add if ctrl=0, subtract if ctrl=1
  42. output [31:0] z;
  43. output cout;
  44. input [31:0] a, b;
  45. input ctrl;
  46. wire [31:0] notB, tmp;
  47. wire cin;
  48.  
  49. // instantiate the components and connect them
  50. assign cin = ctrl;
  51. not my_not [31:0] (notB, b);
  52. yMux #(32) mux(tmp, b, notB, cin);
  53. yAdder adder(z, cout, a, tmp, cin);
  54. endmodulemodule yAlu(z, ex, a, b, op);
  55. input [31:0] a, b;
  56. input [2:0] op;
  57. output [31:0] z;
  58. output ex;
  59. wire cout;
  60. wire[31:0] alu_and,alu_or,alu_arith,slt,tmp;
  61. wire[15:0] z16;
  62. wire[7:0] z8;
  63. wire[3:0] z4;
  64. wire[1:0] z2;
  65. wire z1, z0;
  66.  
  67. assign slt[31:1] = 0;
  68.  
  69. or or16[15:0](z16,z[15:0],z[31:16]);
  70. or or8[7:0](z8,z16[7:0],z16[15:8]);
  71. or or4[3:0](z4,z8[3:0],z8[7:4]);
  72. or or2[1:0](z2,z4[1:0],z4[3:2]);
  73. or or1[15:0](z1,z2[1],z2[0]);
  74.  
  75. not m_not(z0,z1);
  76. assign ex = z0;
  77.  
  78. xor(condition,a[31],b[31]);
  79. yArith slt_arith (tmp,cout,a,b,1);
  80. yMux #(.SIZE(1)) slt_mux(slt[0],tmp[31],a[31],condition);
  81.  
  82. and m_and[31:0] (alu_and,a,b);
  83. or m_or[31:0] (alu_or,a,b);
  84. yArith m_arith (alu_arith,cout,a,b,op[2]);
  85. yMux4to1 #(.SIZE(32))mux(z,alu_and,alu_or,alu_arith,slt,op[1:0]);
  86. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement