题解 | 移位运算与乘法

移位运算与乘法

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 [7:0] d_temp;
always@(posedge clk or negedge rst) begin
    if(!rst) begin
        input_grant<=0;
        out<=11'd0;
        cnt<=2'd0;
        d_temp<=0;
    end
    else begin
        case(cnt)
            2'b00: begin
                out <= d;
                d_temp <= d;
                input_grant <= 1;
                cnt <= cnt+1;
            end 
            2'b01: begin
                out<=d_temp*3;
                input_grant<=0;
                cnt <= cnt+1;
            end
            2'b10: begin
                out<=d_temp*7;
                input_grant<=0;
                cnt <= cnt+1;
            end
            2'b11: begin
                out<=d_temp*8;
                input_grant<=0;
                cnt <= cnt+1;
            end
        endcase
    end
end

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

需要注意的是d_temp和out在input_grant为1是同步采样,因此在一个case item中

可以推知input_grant和out同时assert

全部评论
考虑南京OD的宝子们看过来,你就是我们要找的人,一对一指导,可私信
点赞 回复 分享
发布于 08-09 17:24 贵州

相关推荐

09-24 11:06
辽宁大学 市场
深莞高速因为台风都封掉了,华为协商后,特地开通华为通道,凭工卡可以正常通勤......
崔喃喃:“台风您好,19级专家已驳回了您18级台风的OA登陆申请”
投递华为技术有限公司等公司10个岗位
点赞 评论 收藏
分享
08-05 15:59
已编辑
门头沟学院 运维工程师
哈哈哈,你是老六:感觉这女的就是把你当免费的劳动力
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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