题解 | #移位运算与乘法#

移位运算与乘法

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
全部评论

相关推荐

老板加个卤鸡蛋:HR看了以为来卧底来了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务