题解 | #移位运算与乘法#
移位运算与乘法
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***********// localparam state0 = 2'd0; localparam state1 = 2'd1; localparam state2 = 2'd2; localparam state3 = 2'd3; reg [1:0] state; reg [10:0] tmp; always @( posedge clk or negedge rst ) begin if( !rst ) begin state <= state0; out <= 11'h0; input_grant <= 1'b0; end else begin case( state ) state0: begin input_grant <= 1'b1; out <= {3'b0, d}; tmp <= {3'b0, d}; state <= state1; end state1: begin input_grant <= 1'b0; out <= tmp + (tmp<<1); state <= state2; end state2: begin input_grant <= 1'b0; out <= out + (tmp<<2); state <= state3; end state3: begin input_grant <= 1'b0; out <= (tmp<<3); state <= state0; end endcase end end //*************code***********// endmodule