`timescale 1ns/1ns module multi_sel( input [7:0]d , input clk, input rst, output reg input_grant, output reg [10:0]out ); //*************code***********// wire det_jump; reg [1:0] cnt ; // 用一个计数器作为时间戳 reg [7:0]d_capture ; always@(posedge clk or negedge rst) begin if(~rst) begin cnt <= 0; input_grant <= 0; out <= 0; d_capture <= 0; end else begin cnt <= cnt + 1; case(cnt) 2'b00: begin d_capture <= d; out <= d ; input_grant <= 1'b1; end 2'b01: begin out <= (d_capture<<2)-d_capture; input_grant <= 1'b0; end 2'b10: begin out <= (d_capture<<3)-d_capture; input_grant <= 1'b0; end 2'b11: begin out <= d_capture<<3; input_grant <= 1'b0; end endcase end end //*************code***********// endmodule
仔细看题目 , 发现在input_grant在有值之后的第二个cycle拉高 , 保持1个cycle , 所以可以判断这里使用的D触发器对input_grant进行控制 ,用时序逻辑 。
再看,每个轮回周期 , 是以input_grant此时此刻的值作为4次乘法的输入 , 则我在input_grant = 1 的这个时间点 , 我capture一个值 , 将d赋值给它 , 则当前n时刻的out值为上一时刻n -1 的dff上升沿采样到的d的值。
再往后看 , out的值为X1(第一个时间点 n 的值已经计算完毕 ) X3 X7 X8 ,他们的输入值是什么 , 都是d_capture , 在n时刻 , d_capture已经被latch住了 , 剩下的3个cycle , n+1 , n+2 ,n+3 都会一直使用这个d_capture的值 做计算。
我觉得这个的关键点在于,思考每个时刻寄存器的值是什么,输入是什么,输出是什么,计算反而次要 。