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

移位运算与乘法

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***********//
reg [1:0]cnt;
reg [10:0]d1;

always  @(posedge clk or negedge rst)
begin
if(!rst)begin
    input_grant<=0;
    out<=0;
    cnt<=1'd0;
    d1<=0;
end
else begin
    case(cnt)
    0:begin
        out<=d;
        input_grant<=1;
        d1<=d;
        cnt<=1;
    end
    1:begin
        
        out<=(d1<<2)-d1;
         input_grant<=0;
        cnt<=2;
    end
    2:begin
        out<=(d1<<3)-d1;
        input_grant<=0;
        cnt<=3;
    end
    3:begin
        out<=(d1<<3);
        input_grant<=0;
        cnt<=0;
    end


    endcase

end
end


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

本题考查状态机的用法及左移右移的使用,左右移与加减乘除使用时需要打括号。再就是这题有点没明白是乘d的1378还是在乘完的基础上再乘

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-11 11:24
大家还是用ai改吧,我心疼得要死,就当花钱买教训吧,人家直接拿完钱就跑路了
程序员小白条:简历修改700....神奇,又不是帮你面试,咋的,简历修改从双非变92了还是没实习变成有大厂实习了
点赞 评论 收藏
分享
程序员小白条:军人经历可以去考研考公考编,技术对你真没优势,而且年龄问题
点赞 评论 收藏
分享
认真搞学习:这么良心的老板真少见
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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