#123. 模块与向量信号

    ID: 123 Type: Default 1000ms 256MiB

模块与向量信号

题目描述

对于给定模块 my_dff8,其代码如下所示:

module my_dff8(
input clk,
input [7:0] d,
output reg [7:0] q
);
    always@(posedge clk)
        q <= d;      
endmodule

试创建一 Verilog 模块,对 my_dff8 模块例化 3 次,并串行连接,构成一个 8bit 位宽长度为 3 的移位寄存器,同时可以通过选择信号选择输出结果,如下图所示: image

输入格式

8bit 的任意有效输入

输出格式

根据 sel 信号,选择一个模块或者原输入作为输出信号

示例代码

module my_dff8(
  input clk,
  input [7:0] d,
  output reg [7:0] q
);
    always@(posedge clk)
        q <= d;
endmodule


module top(
  input clk,
  input [7:0] d,
  input [1:0] sel,
  output reg [7:0] q
);
  // Write your code here
endmodule