Advertisement
Shatakshi97

Sequential_multiplier

Mar 25th, 2021
627
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module seq_mul (out,P,a,b,done,clk,rst,start);
  2. output reg done;
  3. output reg[7:0] P;
  4. output reg [7:0] out;
  5. input clk, start , rst;
  6. input [3:0] a , b;
  7. reg C;
  8. reg [3:0] M,N;
  9. parameter s0=2'b00 ,s1=2'b01 ,s2=2'b10 ,s3=4'b11;
  10. reg[1:0] pr_state, next_state;
  11. always @ (posedge clk)
  12. begin
  13. if(start & (!rst))
  14. begin
  15. pr_state<=s0;
  16. M<=a ; N<=b;
  17. C<=0;
  18. end
  19. else
  20. P=8'b00000000;
  21. end
  22.  
  23. always @ (pr_state ,N)
  24. case (pr_state)
  25. s0 : begin
  26.     if(N[0])
  27.     {C,P}= M+P[7:4];
  28.     {C,P}={1'b0,C,P[7:1]};
  29.     next_state = s1;
  30. end
  31.  
  32. s1 : begin
  33.     if(N[1])
  34.      {C,P}= M+P[7:4];
  35.     {C,P}={1'b0,C,P[7:1]};
  36.     next_state = s2;
  37.     end
  38. s2 : begin
  39.     if(N[2])
  40.     {C,P}= M+P[7:4];
  41.     {C,P}={1'b0,C,P[7:1]};
  42.     next_state = s3;
  43.     done=0 ;
  44.     end
  45. s3 : begin
  46.     if(N[3])
  47.          {C,P}= M+P[7:4];
  48.     {C,P}={1'b0,C,P[7:1]};
  49.     done=1;
  50. out = P;
  51.     end
  52. endcase
  53.  
  54. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement