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

移位运算与乘法

https://www.nowcoder.com/practice/1dd22852bcac42ce8f781737f84a3272

`timescale 1ns/1ns
module multi_sel(
input wire [7:0]d ,
input wire clk,
input wire rst,
output reg input_grant,
output reg [10:0]out
);
//*************code***********//
reg [1:0] cnt;
reg [10:0] din;

always@(posedge clk or negedge rst)
    if(!rst)
        cnt<=2'd0;
    else
        cnt<=cnt+1'b1;

always@(posedge clk or negedge rst)
    if(!rst)
        din<=8'd0;
    else if(cnt==2'd0)
        din<=d;
    else
        din<=din;

always@(posedge clk or negedge rst)
    if(!rst)
        input_grant<=1'b0;
    else if(cnt==2'd0)
        input_grant<=1'b1;
    else
        input_grant<=1'b0;

always@(posedge clk or negedge rst)
    if(!rst)
        out<=11'd0;
    else
        case(cnt)
            2'd0 : out<=d;
            2'd1 : out<=din+(din<<1);
            2'd2 : out<=din+(din<<1)+(din<<2);
            2'd3 : out<=din<<3;
        endcase

//*************code***********//
endmodule

全部评论

相关推荐

10-29 15:51
嘉应学院 Java
后端转测开第一人:你把简历的学历改成北京交通大学 去海投1000份发现基本还是没面试
点赞 评论 收藏
分享
算法岗ssp卷了一路,终于上岸了🍠50k*16+签字费+期权,确实是一枝独秀给太多了,碾压🐶42*20+签字费,大概率20拿不满,但给得还是不错🐧还没开,暂时只开了一部分,但大概率也是在原来的超低base基础上涨了1-2k
云烟成yu:兄弟们帮忙选一下: 卷了一路,终于上岸了 字节90k*19+签字费+期权,确实是一枝独秀给太多了,碾压 鹅厂82*20+签字费,大概率20拿满,给得还是不错 其他100个大厂还没开,暂时只开了一部分,但大概率也是在原来的超低base基础上涨了10-20k
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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