Advertisement
Guest User

LE_C2 help

a guest
Nov 21st, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. /Do not change the port declarations
  2. module function_unit (result, VCNZ, OpA, OpB, FS);
  3. input [3:0] FS;
  4. input [7:0] OpA, OpB;
  5. output [7:0] result;
  6. output [3:0] VCNZ;
  7.  
  8. wire FW1, CW1;
  9. wire [7:0] resultb1;
  10. wire [7:0] resultb2;
  11. wire [4:0] b1V1, b2V1;
  12.  
  13. block1 BX(result, arithAselect, arithBselect, arithcarryA);
  14. arith_circuit AC(result, FW1, OpA, OpB, FS);
  15. arithmux AX(result, Fw1, LW1, FS);
  16.  
  17.  
  18.  
  19. arith_circuit ac(resultsb1, b1v1, OpA, OpB, FS);
  20. block1 bc(resultsb2, b2v1, OpA, OpB, FS);
  21.  
  22. assign result = (FS [3] == 1'b0) ? resultb1:
  23. (FS [1] == 1'b1) ? resultb2: 8'bxxxxxxxx;
  24. assign VCNZ = (FS [1] == 1'b0) ? b1v1:
  25. (FS[1] == 1'b1) ? b2v1: 4'bxxxx;
  26.  
  27. endmodule
  28.  
  29. //Replace these assign statement, Vcnz, OpA, OpB, FS);
  30.  
  31.  
  32. //muxes
  33. module arithmux (result4, OpA, OpB, switches);
  34. input [2:0] switches;
  35. input [7:0] OpA, OpB;
  36. output [7:0] result4;
  37. wire [7:0] muxA, muxB;
  38. wire [1:0] Cin, Ra, Rb;
  39.  
  40.  
  41. assign muxA=(Ra ==3'b100) ? OpA : //A
  42. (Ra ==3'b011) ? ~OpA : //~A
  43. (Ra==3'b101) ? 8'b00000000 : //x
  44. (Ra==3'b010) ? 8'b00000000 : //X
  45. 8'bxxxxxxxx;
  46.  
  47. assign muxB=(Rb==3'b001) ? OpB : //B
  48. (Rb ==3'b110) ? ~OpB : //~B
  49. (Rb ==3'b000) ? 8'b00000000 : //x
  50. (Rb ==3'b111) ? 8'b00000000 : //x
  51. 8'bxxxxxxxx;
  52. endmodule
  53.  
  54. ///////////////////////////////////////////////////////////////////////////////
  55.  
  56. //set 1
  57. module arith_circuit (result2,cout1, A, B, select);
  58. input [2:0] select;
  59. input [7:0] A, B;
  60. output [7:0] result2;
  61. wire [7:0] Awire, Bwire, Cwire;
  62. wire [8:1] carry1;
  63. output cout1;
  64.  
  65. arithAselect Ain (A, select, Awire);
  66. arithBselect Bin (B, select, Bwire);
  67. arithcarryA Cin (select, Cwire);
  68.  
  69. full_adders F0 (result2 [0], carry1 [1], A[0],B[0], Cwire);
  70. full_adders F1 (result2 [1], carry1 [2], A[1],B[1],carry1 [1]);
  71. full_adders F2 (result2 [2], carry1 [3], A[2],B[2],carry1 [2]);
  72. full_adders F3 (result2 [3], carry1 [4], A[3],B[3],carry1 [3]);
  73. full_adders F4 (result2 [4], carry1 [5], A[4],B[4],carry1 [4]);
  74. full_adders F5 (result2 [5], carry1 [6], A[5],B[5],carry1 [5]);
  75. full_adders F6 (result2 [6], carry1 [7], A[6],B[6],carry1 [6]);
  76. full_adders F7 (result2 [7], carry1 [8], A[7],B[7],carry1 [7]);
  77.  
  78. assign cout1 =carry1[8];
  79. endmodule
  80. //calling function
  81.  
  82. module full_adders(sum,cout, a, b, cin);
  83. input a, b, cin;
  84. output sum, cout;
  85.  
  86. assign sum = a^b^cin,
  87. cout = a&b | (cin&(a^b));
  88. endmodule
  89. ////////////////////////////////////////////////////////////////////////////////
  90.  
  91.  
  92. /////////////////////////////////////////////////////////////////////////////////
  93.  
  94. // block 1
  95.  
  96. module block1 (result, OpA, OpB, switches);
  97. input [2:0] switches;
  98. input [7:0] OpA, OpB;
  99. output [7:0] result;
  100. wire [7:0] muxB1;
  101.  
  102. // Replace this assign statement with your Verilog code.
  103. // The operation of the arithmetic circuit is defined in the specification.
  104. assign muxB1 =(switches[2:0]==3'b000)?{4'b0000, OpB[3:0]}:
  105. (switches[2:0]==3'b001)?~OpA:
  106. (switches[2:0]==3'b010)?8'b00000000:
  107. (switches[2:0]==3'b100)?~OpB:
  108. (switches[2:0]==3'b110)?OpA|OpB:
  109. (switches[2:0]==3'b101)?~(OpA|OpB):
  110. (switches[2:0]==3'b011)?~(OpA&OpB):
  111. (switches[2:0]==3'b111)?{OpB[4:0],3'b000}: 8'b00000000;
  112. assign result= muxB1;
  113. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement