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

移位运算与乘法

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

全部评论

相关推荐

不吃牛肉的选手在刷面试经:首先,你数过吗?其次,他知道吗?最后,你说了他信吗?
点赞 评论 收藏
分享
03-26 15:18
已编辑
华北水利水电大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务