题解 | 移位运算与乘法

移位运算与乘法

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 贵州

相关推荐

评论
1
收藏
分享

创作者周榜

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