HDLBits刷题Day3,3.1.1.1 - 3.1.1.12

本文介绍了逻辑门的组合使用,包括真值表的构建方法,以及如何用基本逻辑门实现特定的逻辑函数,如A和B的等价判断,电路A和B的组合等。
摘要由CSDN通过智能技术生成

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

 问题描述

假设我们要构建上述电路,但我们仅限于使用一组标准逻辑门。您将如何构建任意逻辑函数(表示为真值表)?创建一个实现上述真值表的组合电路。

真值表可以表示为f=\overline{x1}x2\overline{x3}+x1x2\overline{x3}+x1\overline{x2}x3+x1x2x3=x2\overline{x3}+x1x3

代码:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值