传送门:
nullhttps://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