题解 | #移位运算与乘法#
移位运算与乘法
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]count; reg [7:0]d_r; always@(posedge clk or negedge rst)begin if(!rst)begin count<=0; end else if (count==2'b11) count<=0; else count<=count+1; end always@(posedge clk or negedge rst)begin if(!rst)begin d_r<=0; input_grant<=0; end else if(count==0)begin d_r<=d; input_grant<=1; end else begin d_r<=d_r; input_grant<=0; end end always@(posedge clk or negedge rst)begin if(!rst)begin out<=0; end else case(count) 2'd0 : out <= d; 2'd1 : out <= (d_r<<2)-d_r; 2'd2 : out <= (d_r<<3)-d_r; 2'd3 : out <= (d_r<<3); default : out <= 11'd0; endcase end //*************code***********// endmodule