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

移位运算与乘法

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还是在乘完的基础上再乘

全部评论

相关推荐

刘湘_passion:太强了牛肉哥有被激励到
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务