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