- 已编辑
写在前面:
Hdlbits是学习Verilog的优秀网站,作为刚刚入门的“小菜鸡”,在一刷Hdlbits之后,深感仍有许多知识值得深挖,故而希望在结合其他的优秀资源和安路科技的SparkRoad板子,二刷Hdlbits,达到对Verilog更进一步的理解。
正式开始:
对于Getting Started和Verilog Language的Basics两部分,题目比较基础,略过不谈。
Verilog Language中的Vectors部分个人觉得更偏向于对向量的文字理解。Bitwise operators
其中Bitwise operators提出的位与逻辑运算之间的对比觉得用下图表格理解更容易。
下面附上Vectors部分代码:
Vectors
module top_module (
input wire [2:0] vec,
output wire [2:0] outv,
output wire o2,
output wire o1,
output wire o0 ); // Module body starts after module declaration
assign outv[2:0]=vec[2:0];
assign o2=vec[2];
assign o1=vec[1];
assign o0=vec[0];
endmodule
module top_module(
input wire [15:0] in,
output wire [7:0] out_hi,
output wire [7:0] out_lo );
assign out_hi=in[15:8];
assign out_lo=in[7:0];
endmodule
module top_module(
input [31:0] in,
output [31:0] out );//
assign out[7:0]=in[31:24];
assign out[15:8]=in[23:16];
assign out[23:16]=in[15:8];
assign out[31:24]=in[7:0];
// assign out[31:24] = ...;
endmodule
module top_module(
input [2:0] a,
input [2:0] b,
output [2:0] out_or_bitwise,
output out_or_logical,
output [5:0] out_not
);
assign out_or_bitwise=a|b;
assign out_or_logical=a||b;
assign out_not[5:3]=~b;
assign out_not[2:0]=~a;
endmodule
module top_module(
input [3:0] in,
output out_and,
output out_or,
output out_xor
);
assign out_and=in[3]&in[2]&in[1]&in[0];
assign out_or=in[3]|in[2]|in[1]|in[0];
assign out_xor=in[3]^in[2]^in[1]^in[0];
endmodule
module top_module (
input [4:0] a, b, c, d, e, f,
output [7:0] w, x, y, z );//
assign z[7:0]={e[0],f[4:0],1'b1,1'b1};
assign y[7:0]={d[3:0],e[4:1]};
assign x[7:0]={b[1:0],c[4:0],d[4]};
assign w[7:0]={a,b[4:2]};
endmodule
module top_module(
input [7:0] in,
output [7:0] out
);
assign out[7]=in[0];
assign out[6]=in[1];
assign out[5]=in[2];
assign out[4]=in[3];
assign out[3]=in[4];
assign out[2]=in[5];
assign out[1]=in[6];
assign out[0]=in[7];
endmodule
module top_module (
input [7:0] in,
output [31:0] out );//
assign out = { {24{in[7]}} , in };
endmodule
module top_module (
input a, b, c, d, e,
output [24:0] out );//
wire [24:0]dingbu;
wire [24:0]dibu;
assign dingbu={a,a,a,a,a,b,b,b,b,b,c,c,c,c,c,d,d,d,d,d,e,e,e,e,e};
assign dibu={a,b,c,d,e,a,b,c,d,e,a,b,c,d,e,a,b,c,d,e,a,b,c,d,e};
assign out=~dingbu^dibu;
//assign out = ~{5{a,b,c,d,e}} ^ {{5{a}},{5{b}},{5{c}},{5{d}},{5{e}}};
// The output is XNOR of two vectors created by
// concatenating and replicating the five inputs.
// assign out = ~{ ... } ^ { ... };
endmodule