目录
第1题:Getting Started
构建一个没有输入和一个输出的电路,该输出应始终驱动 1(或逻辑高电平)。
module top_module
(
output one
);
// Insert your code here
assign one = 1'b1;
endmodule
第2题:Output Zero
构建一个没有输入和一个输出常数 0 的输出的电路。
module top_module
(
output zero
);
// Module body starts after semicolon
assign zero = 1'b0;
endmodule
第3题:Simple wire
构建一个具有一个输入和一个输出的模块。
module top_module
(
input wire in,
output wire out
);
assign out = in;
endmodule
第4题:Four wires
构建一个具有 3 个输入和 4 个输出的模块。
module top_module
(
input a,b,c,
output w,x,y,z
);
assign w = a;
assign x = b;
assign y = b;
assign z = c;
endmodule
第5题:Inverter
构建实现一个非门的模块。
module top_module
(
input in,
output out
);
assign out = ~in;
endmodule
第6题:AND gate
构建实现一个与门的模块。
module top_module
(
input a,
input b,
output out
);
assign out = a & b;
endmodule
第7题:NOR gate
构建实现一个或非门的模块,或非门是输出反相的或门。 当用 Verilog 编写时,NOR 函数需要两个运算符。
module top_module
(
input a,
input b,
output out
);
//或非:先或后非,注意和缩位或非'~|'的使用区别
//错误:out = a ~| b;
assign out = ~(a | b);
endmodule
第8题:XNOR gate
构建实现 一个同或门的模块。
module top_module
(
input a,
input b,
output out
);
//同或:相同为1
assign out = ~(a ^ b);
endmodule
第9题:Declaring wires
学习构建两条中间导线将 AND 和 OR 门连接在一起。
`default_nettype none
module top_module
(
input a,
input b,
input c,
input d,
output out,
output out_n
);
/*-----方案1-----*/
// wire ab_out;
// wire cd_out;
// wire mid_out;
// assign ab_out = a & b;
// assign cd_out = c & d;
// assign mid_out = ab_out | cd_out;
// assign out = mid_out;
// assign out_n = ~mid_out;
/*-----方案2-----*/
wire mid_out;
assign mid_out = (a & b) | (c & d);
assign out = mid_out;
assign out_n = ~mid_out;
endmodule
第10题:7458 chip
构建一个与 7458 芯片具有相同功能的模块,它有 10 个输入和 2 个输出, 可以选择使用一条语句来驱动每条输出线,或者选择声明(四条)线用作中间信号,其中每条内部线由一个与门的输出驱动。 如需额外练习,请同时尝试这两种方法。
module top_module
(
input p1a, p1b, p1c, p1d, p1e, p1f,
output p1y,
input p2a, p2b, p2c, p2d,
output p2y
);
/*-----方案1-----*/
// wire p2ab;
// wire p2cd;
// wire p1abc;
// wire p1def;
// assign p2ab = p2a & p2b;
// assign p2cd = p2c & p2d;
// assign p1abc = p1a & p1b & p1c;
// assign p1def = p1d & p1e & p1f;
// assign p1y = p1abc | p1def;
// assign p2y = p2ab | p2cd;
/*-----方案2-----*/
assign p1y = (p1a & p1b & p1c) | (p1d & p1e & p1f);
assign p2y = (p2a & p2b) | (p2c & p2d);
endmodule