Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. // Code your testbench here
  2. // or browse Examples
  3. module tb (
  4. output reg [7:0] inbus ,
  5. output reg bgn,
  6. output reg clk,
  7. output reg rst_b,
  8. output [7:0] outbus,
  9. output fin
  10. );
  11.  
  12. multip m (
  13. .inbus(inbus),
  14. .bgn(bgn),
  15. .clk(clk),
  16. .rst_b(rst_b),
  17. .outbus(outbus),
  18. .fin(fin)
  19. );
  20.  
  21. initial begin
  22. $dumpfile("dump.vcd");
  23. $dumpvars;
  24. end
  25.  
  26. initial begin
  27. clk = 0;
  28. repeat(60) #30 clk = ~clk;
  29. end
  30.  
  31. initial begin
  32. rst_b = 0;
  33. #5 rst_b = 1;
  34. end
  35.  
  36. initial begin
  37. bgn = 1 ;
  38. end
  39.  
  40. initial begin
  41. inbus = 8'b10011001; //-103
  42. #60 inbus = 8'b10000111; //-121
  43. end
  44. endmodule
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56. module multip (
  57. input [7:0] inbus,
  58. input bgn,
  59. input clk,
  60. input rst_b,
  61. output reg [7:0] outbus,
  62. output reg fin);
  63.  
  64. localparam ST0=4'd0;
  65. localparam ST1=4'd1;
  66. localparam ST2=4'd2;
  67. localparam ST3=4'd3;
  68. localparam ST4=4'd4;
  69. localparam ST5=4'd5;
  70. localparam ST6=4'd6;
  71. localparam ST7=4'd7;
  72. localparam ST8=4'd8;
  73. localparam ST9=4'd9;
  74.  
  75. reg [3:0] st, st_nxt;
  76. reg [7:0] M;
  77. reg [8:0] A, Q;
  78. reg [1:0] count;
  79.  
  80. always @(posedge clk, negedge rst_b)
  81. if(!rst_b) st<=ST0;
  82. else st<=st_nxt;
  83.  
  84. always @(st) begin
  85. st_nxt = 4'b0;
  86. fin = 1'b0;
  87. case(st)
  88. ST0:
  89. if(!bgn) st_nxt = ST0;
  90. else st_nxt = ST1;
  91. ST1: begin
  92. Q[8:0] <= {inbus,1'b0};
  93. A <= 9'd0;
  94. count <= 3'b0;
  95. st_nxt <= ST2;
  96. end
  97. ST2: begin
  98. M <= inbus;
  99. st_nxt = ST3;
  100. end
  101. ST3:
  102. if(Q[2:0] == 3'b000 || Q[2:0] == 3'b111)
  103. st_nxt = ST5;
  104. else st_nxt = ST4;
  105. ST4: begin
  106. if(Q[2:0] == 3'b001 || Q[2:0] == 3'b010) A = A + M;
  107. else if(Q[2:0] == 3'b101 || Q[2:0] == 3'b110) A = A - M;
  108. else if(Q[2:0] == 3'b011) A = A + M*2;
  109. else if(Q[2:0] == 3'b100) A = A - M*2;
  110. A[8] = A[7];
  111. st_nxt = ST5;
  112. end
  113. ST5: begin
  114. {A[6:0], Q} <= {A,Q[8:2]};
  115. A[7] <= A[8];
  116. A[8] <= A[8];
  117. st_nxt = ST6;
  118. end
  119. ST6:
  120. if(count == 2'b11)
  121. st_nxt = ST7;
  122. else begin
  123. count <= count + 1;
  124. st_nxt = ST3;
  125. end
  126. ST7: begin
  127. outbus <= Q[8:1];
  128. st_nxt = ST8;
  129. end
  130. ST8: begin
  131. outbus <= A[7:0];
  132. st_nxt = ST9;
  133. end
  134. ST9: begin
  135. fin <= 1'b1;
  136. st_nxt = ST0;
  137. end
  138. endcase
  139. end
  140.  
  141. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement