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

移位运算与乘法

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 [7:0] mid_d;
reg [1:0] cyc;
always @(posedge clk or negedge rst)begin
    if (rst == 0)begin
        mid_d <= 0;
        cyc <= 0;
        input_grant <= 0;
    end
    else 
        if(cyc == 0)begin
            cyc <= cyc+1;
            mid_d <= d;
            input_grant <= 1;
        end
        else begin
            cyc <= cyc+1;
            input_grant <= 0;
        end
end

always @(posedge clk or negedge rst)begin
    if (rst == 0)
        out <= 0;
    else 
        case(cyc)
        2'b00: out <= d;
        2'b01: out <= mid_d*3;
        2'b10: out <= mid_d*7;
        2'b11: out <= mid_d*8;
        endcase
end



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

全部评论

相关推荐

09-24 11:06
辽宁大学 市场
深莞高速因为台风都封掉了,华为协商后,特地开通华为通道,凭工卡可以正常通勤......
崔喃喃:“台风您好,19级专家已驳回了您18级台风的OA登陆申请”
投递华为技术有限公司等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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