Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 0
  1. module srt(input [7:0] IN,
  2. output reg [7:0] QUOTIENT,
  3. output reg [7:0] REMAINDER,
  4. input clk,
  5. input rst);
  6.  
  7. localparam BEGIN = 0;
  8. localparam INA = 1;
  9. localparam INQ = 2;
  10. localparam INM = 3;
  11. localparam NOR = 4;
  12. localparam T1 = 5;
  13. localparam T2 = 6;
  14. localparam COR = 7;
  15. localparam T3 = 8;
  16. localparam OUTQ = 9;
  17. localparam OUTA = 10;
  18. localparam ADD = 11;
  19. localparam SUB = 12;
  20.  
  21. reg [3:0] s_current, s_next;
  22. reg [8:0] a_current, a_next;
  23. reg [7:0] m_current, m_next;
  24. reg [7:0] q_current, q_next;
  25. reg [7:0] q1_current, q1_next;
  26. reg [2:0] count, count_next;
  27. reg [2:0] countc, countc_next;
  28.  
  29. always@( posedge clk, negedge rst)
  30. begin
  31. if(!rst)
  32. begin
  33. a_current<=0;
  34. m_current<=0;
  35. q_current<=0;
  36. q1_current<=0;
  37. count<=0;
  38. countc<=0;
  39. s_current<=BEGIN;
  40. end
  41. else
  42. begin
  43. a_current<=a_next;
  44. m_current<=m_next;
  45. q_current<=q_next;
  46. q1_current<=q1_next;
  47. s_current<=s_next;
  48. count<=count_next;
  49. countc<=countc_next;
  50. end
  51. end
  52.  
  53. always@(*)
  54. begin
  55. a_next=a_current;
  56. m_next=m_current;
  57. q_next=q_current;
  58. q1_next=q1_current;
  59. s_next=s_current;
  60. count_next=count;
  61. countc_next=countc;
  62. QUOTIENT=0;
  63. REMAINDER=0;
  64. case(s_current)
  65. BEGIN:
  66. begin
  67. s_next=INA;
  68. end
  69. INA:
  70. begin
  71. a_next=IN;
  72. s_next=INQ;
  73. end
  74. INQ:
  75. begin
  76. q_next=IN;
  77. s_next=INM;
  78. end
  79. INM:
  80. begin
  81. m_next=IN;
  82. s_next=NOR;
  83. end
  84. NOR:
  85. begin
  86. if(m_current[7]==1)
  87. s_next=T1;
  88. else
  89. begin
  90. m_next={m_current[7:0],1'b0};
  91. a_next={a_current[7:0],q_current[7]};
  92. q_next={q_current[6:0],m_current[7]};
  93. countc_next=countc+1;
  94. s_next=NOR;
  95. end
  96. end
  97. T1:
  98. begin
  99. if(a_current[8:6]==3'b000 || a_current[8:6]==3'b111)
  100. begin
  101. a_next={a_current[7:0],q_current[7]};
  102. q_next={q_current[6:0],1'b0};
  103. q1_next={q1_current[6:0],1'b0};
  104. count_next=count+1;
  105. s_next=T2;
  106. end
  107. else if(a_current[8]==1)
  108. begin
  109. a_next={a_current[7:0],q_current[7]};
  110. q_next={q_current[6:0],1'b0};
  111. q1_next={q1_current[6:0],1'b1};
  112. count_next=count+1;
  113. s_next=ADD;
  114. end
  115. else
  116. begin
  117. a_next={a_current[7:0],q_current[7]};
  118. q_next={q_current[6:0],1'b1};
  119. q1_next={q1_current[6:0],1'b0};
  120. count_next=count+1;
  121. s_next=SUB;
  122. end
  123. end
  124. ADD:
  125. begin
  126. a_next=a_current+m_current;
  127. s_next=T2;
  128. end
  129. SUB:
  130. begin
  131. a_next=a_current-m_current;
  132. s_next=T2;
  133. end
  134. T2:
  135. begin
  136. if(count!=3'b111)
  137. s_next=T1;
  138. else
  139. begin
  140. a_next={a_current[7:0],q_current[7]};
  141. q_next={q_current[6:0],1'b0};
  142. q1_next={q1_current[6:0],1'b0};
  143. s_next=COR;
  144. end
  145. end
  146. COR:
  147. begin
  148. if(a_current[8]==1)
  149. begin
  150. a_next=a_current+m_current;
  151. q_next=q_current-1;
  152. end
  153. s_next=T3;
  154. end
  155. T3:
  156. begin
  157. if(countc!=0)
  158. a_next=a_current>>countc;
  159. s_next=OUTQ;
  160. end
  161.  
  162. OUTQ:
  163. begin
  164. QUOTIENT<=q_current-q1_current;
  165. s_next=OUTA;
  166. end
  167. OUTA:
  168. begin
  169. REMAINDER<=a_current;
  170. end
  171. endcase
  172. end
  173. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement