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

移位运算与乘法

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] count;


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

reg     [10:0]  d_reg;
always@(posedge clk or negedge rst)begin
    if(!rst)begin
        d_reg<=11'd0;
        input_grant<=1'b0;
        out<=11'd0;
    end
    else if(count==0)begin
        d_reg<=d;
        out<=d;
        input_grant<=1'b1;
    end
    else if(count==1)begin
        d_reg<=d_reg;
        out<=d_reg*3;
        input_grant<=1'b0;
    end    
    else if(count==2)begin
        d_reg<=d_reg;
        out<=d_reg*7;
        input_grant<=1'b0;
    end   
    else if(count==3)begin
        d_reg<=d_reg;
        out<=d_reg*8;
        input_grant<=1'b0;
    end 
    else begin
        d_reg<=d_reg;
        input_grant<=input_grant;
        out<=out;
    end          
end


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

这题原理从波形上查看是需要使用一个计数器,用于来控制数据进行乘法,也相当于是进行一个循环位移之后进行乘法计算。主要分成两步首先就是用中间寄存器采集输入数据。

#每日一题挑战#
全部评论

相关推荐

双非阴暗爬行:我来看看笑死我了,这名字取得好想笑(没有不好的意思)
点赞 评论 收藏
分享
迷茫的大四🐶:自信一点,我认为你可以拿到50k,低于50k完全配不上你的能力,兄弟,不要被他们骗了,你可以的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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