3.1.1.1 - 3.1.1.7参考3.1.1.6
3.1.1.6 More logic gates
问题描述
好的,让我们尝试同时构建几个逻辑门。构建具有两个输入a和b的组合电路。
有 7 个输出,每个都有一个逻辑门驱动它:
out_and: a 和 b
out_or:a 或 b
out_xor: a xor b
out_nand: 一个 nand b
out_nor: a 或 b
out_xnor: a xnor b
out_anotb:a 与 b非
代码:
module top_module(
input a, b,
output out_and,
output out_or,
output out_xor,
output out_nand,
output out_nor,
output out_xnor,
output out_anotb
);
assign out_and = a&b; //与门
assign out_or = a|b; //或门
assign out_xor = a^b; //异或门
assign out_nand = ~(a&b); //与非门
assign out_nor = ~(a|b); //或非门
assign out_xnor = a^~b; //同或门
assign out_anotb = a&(~b); //A集合减去B的部分
endmodule
3.1.1.8 Truth tables
问题描述
假设我们要构建上述电路,但我们仅限于使用一组标准逻辑门。您将如何构建任意逻辑函数(表示为真值表)?创建一个实现上述真值表的组合电路。
真值表可以表示为
代码:
module top_module(
input x3,
input x2,
input x1, // three inputs
output f // one output
);
assign f = x2&(~x3) | x1&x3;
endmodule
3.1.1.9 Two bit equality
问题描述
创建一个具有两个 2 位输入A[1:0]和B[1:0]的电路,并产生一个输出z。如果A = B ,则z的值应为 1 ,否则z应为 0。
相关知识:
assign 输出=条件? 输入1:输入2
// 满足条件时,输出=输入1;否则,输出=输入2
代码:
module top_module ( input [1:0] A, input [1:0] B, output z );
assign z = (A==B)? 1'b1:1'b0;
endmodule
3.1.1.10 Simple circuit A
问题描述
模块 A 应该实现函数z = (x^y) & x。实现这个模块。
代码:
module top_module (input x, input y, output z);
assign z = (x^y) & x;
endmodule
3.1.1.11 Simple circuit B
问题描述
电路B可以用下面的仿真波形来描述,实现这个电路:
代码:
module top_module ( input x, input y, output z );
assign z = ~(x^y);
endmodule
3.1.1.12 Combine circuit A and B
问题描述
顶层设计由子电路 A 和 B 的两个实例组成,如下所示。实现这个电路:
代码:
module top_module (input x, input y, output z);
assign z = (((x^y)&x)|(x~^y)) ^ (((x^y)&x)&(x~^y));
endmodule