HDLBits系列入门题目 详解之 Modules: Hierarchy(模块的层次结构)
发布于 2024-09-24 21:15:37(微信公众号导出记录)。
本文来自公众号后台的“导出文章内容”功能。博客正文由导出长图进行本地 OCR 转写,并保留原始排版图用于逐段核对。
原文链接:查看原文
OCR 转写有效文字约 4199 字;代码、流程图和版式以文末原始排版图为准。
正文(本地 OCR 转写)
的层次结构) eEI V1ajero2024年9月24日21:15美国 Module NOTE 设计一个顶层模块,在其中实例化一个名为mod_的子模块。将顶层模块的三个端口、 b和out分别连接到子模块mod_a的三个端口1n1、1n2和out。可以尝试两种 方式连接信号到模块端口:
1.按端口位置连接:
nod_a instancel (a, b, out);
2.按端口名称连接:
nod a instance2 (.in1(a),.in2(b),.out(out)); 这两种方式都可以正确地实现模块的实例化和连接。 module top_module Instantiate one instance of mod_a Make three connections output wire out out input wire top_module Solution nodule top module ( input a, input b, output out ): nod_a instance1 ( in1(a), -in2(b), ,out(out) ); endnodule
Module_pos NOTE 在顶层模映top_moduLe中实例化模块mod_a,并按蓬口位置的顺序将其连接到顶层模块的 端口上。 module top_nodule Instantiate a module mod_a zno 'lino ndano input a, b, out2 top_module Solution nodule top_modulc ( input b, 1nput d, output out2 ) ; nod a instancel ( outl, out2, a, b, c, d ); endnodule
Module name NOTE 在顶层模块top_moduLe中实例化模块mod_a,并按照端口名称的对应关系连接到顶层模块 T口 module top_module
zino'iino ndano input a, b, out2 top_module Solution nodule top_module ( input b, input d, output out1, output out2 nod_a instance1 ( ,out1(outl),out2(out2), in1(a) ,。 -in2(b),.in3(c), -in4(d) 1: endnodule
L
Mismatch Module shift NOTE 实例化三个my_dff 模块,并将它们患联超来形成一个长度为3的移位寄存器。每个实例的 clk口都需要连接到同一个时钟信号。 nodule top_nodule Instantiate 3 moduiles and wires my_dff input clk, output q top_module Solution nodule top_module ( Lnput clk, input d, output q ); vire q1, q2; my_dff d1 ( .ctk(clk), d(d), -q(q1) ); ny_dff d3 ( -clk(c1k),.d(q2), -q(q) ); endnodule
Module shift8 NOTE 实例化三个my_dff8模块,将它们半联形成一个8位宽、3级深的移位寄存器。同时,我们 需要设计一个4选1的多路复用器,根据sel[1:0]的值选择输出从输入d经过9到3 个时特网期的延退值。 otnpcudo1 otnpou
input clk, top_module Solution )onpou do1 anpou 1nput clk, ‘p[o:] 1ndu] input [1:e] scl, b[e:1 1nd1no : ( wire [7:e] q1, q2, q3; my_dff8 d1 ( .clk(cik), .d(d), -q(q1) ); my_dff8 d3 ( .clk(clk), d(q2), q(q3) ); always @() bcgin case(sel) :p = b :00q.z 2b01: q = q1; 2’b11: q = q3:; endcase end endnodule
XXbXXeXXX3
Module_add NOTE 需要实例化两个add16模块来实现一个32位加法器。第一个add16模块计算低16位的 加法结果,第二个add16模块计算高16位的加法结果,并接收第一个加法器的进位输出。 add16 cin [osL]e 32 sum[15:0] b[15:0] 3no3 add16 cin a[15:0] sum[15:0] b[15:0] cout top_module Solution nodule add1( input a, b, cin, c1n, putput sun, cout 7 F assign sun = a ^ b ^ cin; endnodule )anpoa do1 anpou input [31:0] b, uns[g:tE]ndno ) ; wire cout_low; add16 low(a[15:0], b[15:a] , 1*be, sum[15:0]。 cout_low); add16 high(a[31:16] , b[31:16], cout_lov, sun[31:16] . ); endnodule
1X X2c1 2 X1X2X3XmFX10000X3c0 0 X1X2X3XffX100003cc0 SUm
Module_fadd NOTE 创建一个具有两级层次结构的电路。顶层模块top_module将实例化两个add16模块,而每 个add16模块又将实例化16个add1模块。因此,我们塞要实现两个模块:top_nodule 和 addl。 两个add16模块,一个计算低 16位的加法结果,另一个计算高16位的加法结果。两个 add16模块之间通过Lower_cout进位输出连接,以实现32位加法。最后,我们将两个 add16硬块的辅出拼接起来,赋值给顶层模块的sun 输出端口。通过这种方式,实现了一个 32位加法器,由两个级联的add16模块组成,每个add16 模块又由16个addl全加器 模块构成。 top_module mnodule top_module x1 add16 cin nodule add16 x2 add1 cin module add1 x32 no add1 cin sum add1 cin Sum cout
SUm 9ppe a[15:0] [o:s L]wns b[15:0] cout
Solution nodule add1( input a, b, cin, output sun, cout 7 ; = uns uftsse cin; assign cout = (o & b) 1 (cin 5 (a ^ b)); endnodule nodule top_rodulc( 1nput [31:0] a, ‘q[0:te] 1ndu] output [31:0] sum 7 wire cout_low; add16 low(a[15:0], b[15:9] , 1'be, sum[15:0] , cout_low); add16 high(a[31:16] , b[31:16] , cout_lov, sun[31:161, ); endnodule 0 1 U 3 4X6XfFX10000 X2X ] 1X4X6XffX10000 sum 0 Mismatch: Module_cseladd NOTE 实现一个 32位的 carry-select 加法器,它由三个 add16 模块和一个 16位 2 选1 多路复用器组成。 add16 cin a[15:0] sum[15:0] b[15:0] cout add16 cin a[15:0] sum[15:0] b[15:0] cout [31:16] add16 cin a[15:0] sum[15:0] [0sL]uns b[15:0] top_module cout Solution module top_module( input [31:0] b, output [31:0] sum wire cout_low, cout_higho, cout_highl; wire [15:0] sum_high0, sum_high1; add16 low(a[15:0], b[15:0], 1'b0, sum[15:0], cout_low); add16 high0(a[31:16], b[31:16], 1'b0, sum_highe, cout_high0) ; add16 high1(a[31:16], b[31:16], 1'b1, sum_high1, cout_high1) ; assign sum[31:16] = cout_low ? sum_high1 : sum_high0; 13 endmodule 0 1 X2ccc1 1 2 0 1 3ccc0 10000 2 册 sum 3 1 ] 10000 sum fff 0 1 2 3 3ccc0 Mismatch: 15 20 25 10 Module addsub NOTE 实现一个32位的加减法器,它由两个add16模块和一个32位的异或门组成。 sub add16 cin a[15:0] 32 sum[15:0] b[15:0] cout sub sum add16 cin a[15:0] [31-16] sum[15:0] b[15:0] cout top_module Solution module top_module( input [31:0] a, input sub, output [31:0] sum wire [31:0] b_xor; wire cout_low; assign b_xor =b ^{32{sub}}; 1 add16 low(a[15:0], b_xor[15:0], sub, sum[15:0], cout_low); add16 high(a[31:16], b_xor[31:16], cout_low, sum[31:16], ) ; endmodule fff 10000 ff 1 sub 10000 le ff sum D 0 sum 10000 fff fe 0 0 1 2 Mismatch:
FPGA·目录三 <上一篇·HDLBits系列入门题目详解之Vector
原始排版图

