【计算机系统要素】使用Nand实现各种基本逻辑门

本文是笔者拜读《计算机系统要素》第1章(布尔逻辑)的实践项目,本文的HDL遵循的是书中的语法,并在配套的硬件仿真器中测试成功。

Nand门(与非门)是最原始的门,其它门都是由该门构建的。
在这里插入图片描述

非门

在这里插入图片描述
out=Nand(in,true)

CHIP Not {
   
    IN in;
    OUT out;

    PARTS:
    // Put your code here:
    Nand(a = in, b = true, out = out);
}

HDL中的=表示连接,而不是“赋值”。

与门

在这里插入图片描述
out = Not(Nand(a,b))

CHIP And {
   
    IN a, b;
    OUT out;

    PARTS:
    // Put your code here:
    Nand(a = a, b = b, out = c);
    Not(in = c, out = out);
}

或门

在这里插入图片描述
out=Nand(Not(a),Not(b))out=Nand(Nand(a,a),Nand(b,b))
Nand(a,a)相当于Not(a)

CHIP Or {
   
    IN a, b;
    OUT out;

    PARTS:
    // Put your code here:
    Not(in = a, out = na);
    Not(in = b, out = nb);
    Nand(a = na, b = nb, out = out);
}

异或门

在这里插入图片描述
out = Or(And(a,Not(b)), And(Not(a), b))

CHIP Xor {
   
    IN a, b;
    OUT out;

    PARTS:
    // Put your code here:
    Not(in = a, out = na);
    Not(in = b, out = nb);
    And(a = a, b = nb, out = out1);
    And(a = na, b = b, out = out2);
    Or(a = out1, b = out2, out = out);
}

多路复用

二选一选择器
在这里插入图片描述
out = Or(And(Not(sel),a),And(sel,b))

CHIP Mux {
   
    IN a, b, sel;
    OUT out;

    PARTS:
    // Put your code here:
    Not(in = sel, out = nsel);
    And(a = a, b = nsel, out = out1);
    And(a = b, b = sel, out = out2);
    Or(a = out1, b = out2, out = out);
}

多路分解

在这里插入图片描述
a=And(in, Not(sel))
b=And(in,sel)

CHIP DMux {
   
    IN in, sel;
    OUT a, b;

    PARTS:
    // Put your code here:
    Not(in = sel, out = nsel);
    And(a = in, b = nsel, out = a);
    And(a = in, b = sel, out = b);
}

多位非门

在这里插入图片描述

CHIP Not16 {
   
    IN in[16];
    OUT out[16];

    PARTS:
    // Put your code here:
    Not(in = in[0], out = out[0]);
    Not(in = in[1], out = out[1]);
    Not(in = in[2], out = out[2]);
    Not(in = in[3], out = out[3]);
    Not(in = in[4], out = out[4]);
    Not(in = in[5], out = out[5]);
    Not(in = in[6], out = out[
  • 12
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值