HDLBits(4)——15-19
第十六题:给定一个8bit输入向量,将其反向输出。
下面是一个笨方法。
1 assign {x[0],x[1],x[2]……,x[7]} = in;
若是数据有1024bit,需要使用循环。
1 for(i=0;i<8;i=i+1) 2 out[i]=in[8-i-1];

这里出现了生成块的概念,看了讲解,还是看不懂。
在以后的使用过程中多体会区别吧。
1 generate 2 genvar i; 3 for (i=0; i<8; i = i+1) begin: my_block_name 4 assign out[i] = in[8-i-1]; 5 end 6 endgenerate
第十七题:Replication operator(重复操作符)
第十八题:More Replication
1 module top_module ( 2 input a, b, c, d, e, 3 output [24:0] out );// 4 5 // The output is XNOR of two vectors created by 6 // concatenating and replicating the five inputs. 7 // assign out = ~{ ... } ^ { ... }; 8 assign out = ~{{5{a}},{5{b}},{5{c}},{5{d}},{5{e}}} ^ {{5{a,b,c,d,e}}}; 9 endmodule
第十九题:modules
在一个模块中可以例化下一级的模块,这就形成了层级的概念(hierarchy)。
时刻记住,在例化过程中,出现在前面的是本模块的接口(即例化模块)
1 module top_module ( input a, input b, output out ); 2 mod_a U_mod_a( 3 .in1(a) 4 , .in2(b) 5 , .out(out)); 6 //mod_a U_mod_a(a, .b, out); //使用按照端口顺序的方式 声明信号连接 7 endmodule
注意写法,引用原答主:
至于逗号放在前面还是放在后面,那倒无所谓。但我看过 NVIDIA 的开源代码将逗号放在前面之后,觉得这样挺好的,故也就这么写了。

浙公网安备 33010602011771号