实施逻辑门的直觉 [英] Intuition for implementing logic gates

查看:61
本文介绍了实施逻辑门的直觉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被要求以半HDL语言实现逻辑门以进行练习.问题是我对实现缺乏直觉,看不到用于转向"目标的方法或算法.逻辑表的真值表,甚至更简单的逻辑门(如XOR);怎样才能转变"?几个逻辑门形式的运算符?到现在为止,该练习感觉像是尝试逻辑门的所有可能组合".我想那不是那样的.

I've been asked to implement logic gates in semi-HDL language for an exercise. The problem is that I'm lack of intuition regarding the implementations and can't see a method or algorithm for "turning" a truth-table into logic gates, even the more simple one (like XOR); how can one "transform" an operator into the form of several logic gates? Until now the exercise feels like "trying all possible combinations of logic gates" and I guess that it souldn't be like that.

推荐答案

由于原始问题被标记为 nand2tetris 我认为答案是正确的.

Since the original question is tagged with nand2tetris I think a different answer is in order.

如果您正在通过这本书第1周中介绍Xor的实现.本书在第1章中介绍了Xor.在这里,我将了解我对这本书的解释.

If you're working through the book or the coursera course, then you should have the information already available to work through this yourself. However, I also struggled with this because it was new to me so maybe I understand what you're going through and can help. The coursera course should cover the implementation of Xor in Week 1. The book covers Xor in Chapter 1. I will walk through my understanding of the book's explanation here.

作者要求人们不要在互联网上提供问题的答案.但是,Xor的答案是本书的作者提供的全部内容,您可以在第16页上找到.鉴于此,我将继续在这里提供自己的解释.

The authors have asked folks not to provide answers to the problems on the internet. However, the answer for Xor is worked through and provided by the authors in the book, you can find it on page 16. Given this, I'm going to go ahead and provide my own explanation here.

要实现Xor,您需要了解作者所说的以下内容:

In order to implement Xor, you need to understand the following bits of what the authors say:

  1. " ......每个布尔函数都可以使用至少一个布尔表达式来表达,该布尔表达式称为"规范表示形式" 第9页
  2. ",从函数的真值表开始,我们关注函数具有值1的所有行.对于每一个这样的行,我们构造一个由与"(Anding)字面量(变量或它们的取反)创建的术语.),固定所有行输入的值." 第9页
  3. "现在,如果我们将所有这些术语(对于函数具有value1的所有行)或在一起,我们将得到一个布尔表达式,该布尔表达式等效于给定的真值表." 第9页
  4. ".这得出一个重要的结论:每个布尔函数,无论多么复杂,都只能使用三个布尔运算符来表示:与,或,和非". page9
  1. "... every Boolean function can be expressed using at least one Boolean expression called the canonical representation", page 9
  2. "Starting with the function’s truth table, we focus on all the rows in which the function has value 1. For each such row, we construct a term created by And-ing together literals(variables or their negations) that fix the values of all the row’s inputs.", page 9
  3. "Now, if we Or-together all these terms (for all the rows where the function has value1), we get a Boolean expression that is equivalent to the given truth table.", page 9
  4. "This ... leads to an important conclusion: Every Boolean function, no matter how complex, can be expressed using three Boolean operators only: And, Or, and Not", page9

因此,如果您要实现布尔逻辑门(如Xor那样),则可以通过写下其真值表,写下该真值表的规范表示,然后实现布尔逻辑门来实现.在HDL中,使用按规范表示法指定的与",或"和非"门的组合.

Therefore, if you're trying to implement a boolean logic gate (as Xor is), you can do so by writing down its truth table, writing down the canonical representation of that truth table, and then implementing the boolean logic gate in HDL using a combination of And, Or, and Not gates as specified by the canonical representation.

这是Xor的工作原理:

Here's how it works for Xor:

  1. 写下Xor的真值表:

a  b   out 
0  0 |  0  
0  1 |  1  
1  0 |  1  
1  1 |  0

  1. 写下Xor真值表的规范表示形式:

(!a && b) || (a && !b)

  1. 在HDL中实施规范表示:

CHIP Xor {
    IN a, b;
    OUT out;

    PARTS:
    // !a && b
    Not(in=a, out=nota);
    And(a=nota, b=b, out=lhs);
    // a && !b
    Not(in=b, out=notb);
    And(a=a, b=notb, out=rhs);

    // (!a && b) || (a && !b)
    Or(a=lhs, b=rhs, out=out);
}

就是这样.

具体来说,我认为您可能需要学习以自行解决此问题的技术是如何写下真值表的规范表示形式.因此,请尝试并弄清楚我是如何得到的从第1步到第2步,如果您有任何问题,请在此处询问.请记住,这本书和Coursera课程都详细介绍了如何执行此操作,我在上面引用了本书中最相关的部分.

Specifically, I think the technique you probably need to learn to solve this problem on your own is how to write down the canonical representation of a truth table. Therefore, try and work out how I got from step 1 to step 2 and if you have questions ask them here. Remember that the book and coursera course both go over exactly how to do this and I've quoted the most relevant bits from the book above.

我希望这会导致您正在寻找的直觉.祝你好运.

I hope this leads to the intuition you're looking for. Best of luck.

这篇关于实施逻辑门的直觉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆