当前位置: 首页 > news >正文

0291-Nand-实现基础逻辑门(一)

环境

  • Time 2023-07-06

前言

说明

参考:https://www.nand2tetris.org/

目标

通过最基础的 Nand(与非门)实现 Not、And、Or、Xor、Mux、DMux 几个基础门。

Not

/*** Not gate:* out = not in*/
/** Sets out = in Nand in */
CHIP Not {IN in;OUT out;PARTS:// Put your code here:Nand(a = in, b = in, out = out);
}

And

/*** And gate:* out = 1 if (a == 1 and b == 1)*       0 otherwise*/
/** Sets out = Not(a Nand b) */
CHIP And {IN a, b;OUT out;PARTS:// Put your code here:Nand(a = a, b = b, out=aNandb);Not(in = aNandb, out = out);
}

Or

 /*** Or gate:* out = 1 if (a == 1 or b == 1)*       0 otherwise*/
/** Sets out = Not(Not(a) And Not(b)) */
CHIP Or {IN a, b;OUT out;PARTS:// Put your code here:Not(in = a, out = Nota);Not(in = b, out = Notb);And(a = Nota, b = Notb, out = NotaAndNotb);Not(in = NotaAndNotb, out = out);
}

Xor

/*** Exclusive-or gate:* out = not (a == b)*/
/** Sets out = ((a And Not(b)) Or (Not(a) And b)) */
CHIP Xor {IN a, b;OUT out;PARTS:// Put your code here:Not(in = b, out = Notb);And(a = a, b = Notb, out = aAndNotb);Not(in = a, out = Nota);And(a = Nota, b = b, out = NotaAndb);Or(a = aAndNotb, b = NotaAndb, out = out);
}

Mux

/*** Multiplexor:* out = a if sel == 0*       b otherwise*/
/** Sets out = ((a And Not(sel)) Or (b And sel)) */
CHIP Mux {IN a, b, sel;OUT out;PARTS:// Put your code here:Not(in = sel, out = Notsel);And(a = a, b = Notsel, out = aAndNotsel);And(a = b, b = sel, out = bAndsel);Or(a = aAndNotsel, b = bAndsel, out = out);
}

DMux

/*** Demultiplexor:* {a, b} = {in, 0} if sel == 0*          {0, in} if sel == 1*/
/** Sets a = (in And (Not(sel))) */
/** Sets b = (in And sel) */
CHIP DMux {IN in, sel;OUT a, b;PARTS:// Put your code here:Not(in = sel, out = Notsel);And(a = in, b = Notsel, out = a);And(a = in, b = sel, out = b);
}

总结

使用 Nand 这一个最基础的逻辑门,实现其它的基础逻辑门。

附录

http://www.gsyq.cn/news/35091.html

相关文章:

  • NASM下载和安装教程(附安装包)
  • 0292-Nand-实现基础逻辑门(二)
  • 单点登录SSO是怎么实现的?
  • 2025年上海房产继承律师权威推荐榜单:继承律师/离婚律师/婚姻律师事务所精选
  • autotiny下载_v3.0.0.2
  • Python嵌套_多条件判断 _ 对象今天会生气吗 II
  • 解析视频融合平台EasyCVR的分析平台技术如何成为“全域视频管理中台”
  • 2025年10月logo/VI设计专业公司权威推荐排行榜:探索年最佳设计服务
  • 深入解析:GitPuk入门教程:安装及使用指南,一文轻松上手
  • 完整教程:Linux启动流程与字符设备驱动详解 - 从bootloader到驱动开发
  • 学术会议会议合集 | 电子信息工程、计算机技术、文学、人文发展、数字经济等EI会议合集
  • 2025 年弯管机生产厂家最新推荐榜,技术实力与市场口碑深度解析且高性能与可靠性兼具四轴/双轴/双层膜弯管机公司推荐
  • 2025年智慧厕所厂家权威推荐榜单:智慧厕所智能水表/智慧公厕系统/智慧厕所源头厂家精选
  • 用Circom和Snarkjs实践零知识证明技术
  • ubuntu24 输入法优化
  • 基于DCT变换和Huffman编码的图像压缩解压缩算法matlab性能仿真
  • 2025年络合铁脱硫剂厂家爱权威推荐榜单:沼气脱硫剂/天然气脱硫剂 /铁基脱硫剂源头厂家精选
  • K8s学习笔记(十二) volume存储卷 - 实践
  • 2025 年微孔分析仪厂家最新推荐榜,技术实力与市场口碑深度解析,筛选高性能可靠优质品牌
  • 机器视觉在半导体行业的重要性(以51camera晶圆隐裂检测系统为例)
  • 2025年水式喷砂机定做厂家爱权威推荐榜单:小五金件喷砂/数控喷砂机 /管壁喷砂机厂家精选
  • 2025年质量好的上料搅拌车最新TOP厂家排名
  • 蓝牙基础(一):蓝牙软硬件架构介绍
  • 微波雷达和毫米波雷达有什么区别
  • 2025年比较好的纺织橡胶辊品牌厂家排行榜
  • 2025年热门的轨道交通硅胶制品行业内知名厂家排行榜
  • Fluid 正式入驻青云 KubeSphere Marketplace,共建云原生数据加速新生态
  • 2025年口碑好的防水三防灯用户好评厂家排行
  • 单独学智能体,是永远无法变现的
  • 2025年可靠的公园音乐喷泉行业内知名厂家排行榜