题解 | #移位运算与乘法#
移位运算与乘法
http://www.nowcoder.com/practice/1dd22852bcac42ce8f781737f84a3272
reg [7:0] d_cal;
reg [1:0] state;
// 状态 always @ (posedge clk or negedge rst)begin
if(!rst) begin
out <= 11'd0;
state <= 2'd0;
d_cal <= 0;
input_grant <= 1'b0;
end
else begin
case(state)
2'd0: begin d_cal <= d; out <= d; state <= 2'd1; input_grant <= 1'b1; end
2'd1: begin out <= (d_cal << 1) + d_cal; state <= 2'd2; input_grant <= 1'b0; end
2'd2: begin out <= (d_cal << 2) + (d_cal << 1) + d_cal; state <= 2'd3; input_grant <= 1'b0; end
2'd3: begin out <= (d_cal << 3); state <= 2'd0; input_grant <= 1'b0; end
default:;
endcase
end
end
