题解 | 移位运算与乘法
移位运算与乘法
https://www.nowcoder.com/practice/1dd22852bcac42ce8f781737f84a3272
`timescale 1ns/1ns module multi_sel( input [7:0]d , input clk, input rst, output reg input_grant, output reg [10:0]out ); //*************code***********// reg [1:0] cnt; reg [7:0] d_temp; always@(posedge clk or negedge rst) begin if(!rst) begin input_grant<=0; out<=11'd0; cnt<=2'd0; d_temp<=0; end else begin case(cnt) 2'b00: begin out <= d; d_temp <= d; input_grant <= 1; cnt <= cnt+1; end 2'b01: begin out<=d_temp*3; input_grant<=0; cnt <= cnt+1; end 2'b10: begin out<=d_temp*7; input_grant<=0; cnt <= cnt+1; end 2'b11: begin out<=d_temp*8; input_grant<=0; cnt <= cnt+1; end endcase end end //*************code***********// endmodule
需要注意的是d_temp和out在input_grant为1是同步采样,因此在一个case item中
可以推知input_grant和out同时assert