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

移位运算与乘法

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

全部评论

相关推荐

06-02 15:53
阳光学院 Java
点赞 评论 收藏
分享
06-04 09:27
门头沟学院 Java
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
06-20 18:18
是不是意味着秋招就完蛋了
花不开柳成荫:如果你是Java,是的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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