Guest User

Untitled

a guest
May 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. `define DEBUG
  2.  
  3. module add(
  4. input wire clk,rst,
  5. input logic [N-1:0] X1,Z1,Xm,Zm,Xn,Zn,
  6. output logic [N-1:0] Xmn,Zmn
  7. `ifdef DEBUG
  8. ,output wire [3:0] o_count,
  9. output wire [1:0] o_in_sel0,o_in_sel1,o_in_sel2,
  10. output wire [N-1:0] o_calc_out0,o_calc_out1,o_calc_out2,
  11. output wire [N-1:0] o_memory_out0,o_memory_out1,o_memory_out2,o_memory_out3,o_memory_out4,o_memory_out5
  12. `endif
  13. );
  14.  
  15. parameter N = 16;
  16.  
  17. logic inf;
  18. logic [N-1:0] calc_out[2:0];
  19. logic [N-1:0] memory_out[5:0];
  20. logic [1:0] in_sel[2:0];
  21. logic [3:0] out_sel[5:0];
  22. logic [3:0] count;
  23.  
  24. adder adder1(memory_out[0],memory_out[1],calc_out[0]);
  25. subtractor subtractor1(memory_out[2],memory_out[3],calc_out[1]);
  26. multiplier multiplier3(memory_out[4],memory_out[5],calc_out[2]);
  27. memory_a memory_a1(clk,rst,in_sel,out_sel,X1,Z1,Xm,Zm,Xn,Zn,calc_out,memory_out);
  28.  
  29. initial begin
  30. count=4'b0000;
  31. in_sel='{2'b10,2'b01,2'b00};
  32. out_sel='{4'b0000,4'b0000,4'b0011,4'b0010,4'b0101,4'b0100};
  33. end
  34.  
  35. `ifdef DEBUG
  36. assign o_count=count;
  37. assign o_in_sel0=in_sel[0];
  38. assign o_in_sel1=in_sel[1];
  39. assign o_in_sel2=in_sel[2];
  40. assign o_calc_out0=calc_out[0];
  41. assign o_calc_out1=calc_out[1];
  42. assign o_calc_out2=calc_out[2];
  43. assign o_memory_out0=memory_out[0];
  44. assign o_memory_out1=memory_out[1];
  45. assign o_memory_out2=memory_out[2];
  46. assign o_memory_out3=memory_out[3];
  47. assign o_memory_out4=memory_out[4];
  48. assign o_memory_out5=memory_out[5];
  49. `endif
  50.  
  51. always @(posedge clk or negedge rst) begin
  52. if(rst==0) begin
  53. count=4'b0000;
  54. in_sel='{2'b10,2'b01,2'b00};
  55. out_sel='{4'b0000,4'b0000,4'b0011,4'b0010,4'b0101,4'b0100};
  56. end else begin
  57. case(count)
  58. 4'b0000:begin
  59. if(Zm==0 || Zn==0)begin
  60. inf=1;
  61. Xmn=Zm==0?Xn:Xm;
  62. Zmn=Zm==0?Zn:Zm;
  63. end else begin
  64. inf=0;
  65. end
  66. in_sel='{2'b10,2'b01,2'b00};
  67. out_sel='{4'b0111,4'b0110,4'b0101,4'b0100,4'b0011,4'b0010};
  68. count=4'b0001;
  69. end
  70. 4'b0001:begin
  71. in_sel='{2'b10,2'b01,2'b00};
  72. out_sel='{4'b0111,4'b0110,4'b0000,4'b0000,4'b0000,4'b0000};
  73. count=4'b0010;
  74. end
  75. 4'b0010:begin
  76. in_sel='{2'b11,2'b01,2'b00};
  77. out_sel='{4'b0000,4'b0000,4'b1001,4'b1000,4'b1001,4'b1000};
  78. count=4'b0011;
  79. end
  80. 4'b0011:begin
  81. in_sel='{2'b10,2'b01,2'b00};
  82. out_sel='{4'b0110,4'b0110,4'b0000,4'b0000,4'b0000,4'b0000};
  83. count=4'b0100;
  84. end
  85. 4'b0100:begin
  86. in_sel='{2'b10,2'b11,2'b00};
  87. out_sel='{4'b0111,4'b0111,4'b0000,4'b0000,4'b0000,4'b0000};
  88. count=4'b0101;
  89. end
  90. 4'b0101:begin
  91. in_sel='{2'b11,2'b01,2'b00};
  92. out_sel='{4'b1000,4'b0001,4'b0000,4'b0000,4'b0000,4'b0000};
  93. count=4'b0110;
  94. end
  95. 4'b0110:begin
  96. in_sel='{2'b10,2'b01,2'b00};
  97. out_sel='{4'b1001,4'b0000,4'b0000,4'b0000,4'b0000,4'b0000};
  98. count=4'b0111;
  99. end
  100. 4'b0111:begin
  101. if(inf==0)begin
  102. Xmn=calc_out[2];
  103. end
  104. in_sel='{2'b10,2'b01,2'b00};
  105. out_sel='{4'b0000,4'b0000,4'b0011,4'b0010,4'b0101,4'b0100};
  106. count=4'b1000;
  107. end
  108. 4'b1000:begin
  109. if(inf==0)begin
  110. Zmn=calc_out[2];
  111. end
  112. count=4'b1111;
  113. end
  114. default:begin
  115. //nothing to do
  116. end
  117. endcase
  118. end
  119. end
  120.  
  121. endmodule
Add Comment
Please, Sign In to add comment