题解 | 移位运算与乘法

移位运算与乘法

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 [1:0] mul_case = 0;
    reg [7:0] d_reg = 0;


    always @(posedge clk or negedge rst) begin
        if (!rst) begin
            out <= 0;
            d_reg<=d;
            input_grant <= 0;
        end else begin
            case (mul_case)
                2'b00: begin
                    d_reg<=d;
                    input_grant <= 1;
                    out<=d;
                end
                2'b01: begin
                    out <= (d_reg << 1) + d_reg;
                    input_grant <= 0;
                    
                end
                2'b10: begin
                    out <= (d_reg << 3) - d_reg;
                    input_grant <= 0;
                    
                end
                2'b11: begin
                    out <= (d_reg << 3);
                    input_grant <= 0;
                    
                end
            endcase

        end
    end

    always @(posedge clk or negedge rst)begin
        if(!rst) begin
            mul_case<=2'b00;
        end else begin
            mul_case<=mul_case+2'b1;
        end
    end

endmodule  //shift_mul

状态机要单独写在另一个always块中,不然会扰乱时序!!!

全部评论

相关推荐

看新闻上说,印度媒体都在密集发申请攻略,咨询量直接涨了30%印度、韩国、新加坡的申请意愿特别突出,感觉要成科技人才的新选择了~我的offer还没有呢!
ysb:哥们就不明白了,自己的人才都留不住,然后找外国,咋滴给外国人才高福利朝九晚五不加班是吗,然后我们大学生996,加班,无offer,摆地摊,送外卖是吗,有点意思,很英明
我的秋招日记
点赞 评论 收藏
分享
星期一的大老师:项目描述 和 技术栈单开一栏;八股文:算法与数据结构,计算机网络一定要写,操作系统不了解可以不写;Linux命令,Git,Docker基础命令和基本使用一定要写,要有实际使用场景的解决经验;项目的八股文上:redis 解决 缓存雪崩,缓存击穿,缓存穿透的解决方案,一个问题的不同方案可以一起用,不需要重复在两个项目写。第二个项目换一个。小厂可以投一投
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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