Verilog :Exams/2014 q4b/n bit 移位寄存器

传送门:

nullicon-default.png?t=N7T8https://hdlbits.01xz.net/wiki/Exams/2014_q4b题目:

为移位寄存器编写一个顶层模块( top_module),假设 n = 4。顶层模块实例化 4 个  MUXDFF 子模块。假设您将在 DE2 板上实现电路。

  • Connect the R inputs to the SW switches,
  • clk to KEY[0],
  • E to KEY[1],
  • L to KEY[2], and
  • w to KEY[3].
  • Connect the outputs to the red lights LEDR[3:0].

以下为本人提供的代码,有更好的代码欢迎评论区提供:

module top_module (
    input [3:0] SW,
    input [3:0] KEY,
    output [3:0] LEDR
); //
    wire clk = KEY[0];
    wire E = KEY[1];
    wire L = KEY[2];
    wire w = KEY[3];

    MUXDFF mux1(clk,w,SW[3],E,L,LEDR[3]);
    MUXDFF mux2(clk,LEDR[3],SW[2],E,L,LEDR[2]);
    MUXDFF mux3(clk,LEDR[2],SW[1],E,L,LEDR[1]);
    MUXDFF mux4(clk,LEDR[1],SW[0],E,L,LEDR[0]);
    
endmodule

module MUXDFF  (
    input clk,
    input w, R, E, L,
    output Q
);
always @(posedge clk) begin
    Q <= L?R:(E?w:Q);
end
endmodule

  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值