How to use the hardware simulaitor? how can i impelement a nad gatter in a hdi?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to use the hardware simulaitor? how can i impelement a nad gatter in a hdi?

kiohoilgb8
Hi, I read the hole pdf, but idnot understood it...

For example I have:

CHIP t {
    IN a,b;
    OUT out;

    PARTS:

}

This is the beginning of the HDI, how can I use the nand gatter?
Our Prof said that we could use the nand gatter easy, but he didnot say how... For example I want to have a nand getter, how would i make it, that the output is like the output from a nade gate? Should I give the inputs a and b a value or not? Our prof said, that the nand gate is a default setting, so we can use that, without own implements, but I dont now the syntax how to use.

Would be this correct?:

CHIP t {
    IN a,b;
    OUT out;

    PARTS:
    NAND(a=true, b=false)
    // I think so give the inputs a value, but how can i now say, that the output is like a nand?
}

And I have to give the values a name or i dont need?
Reply | Threaded
Open this post in threaded view
|

Re: How to use the hardware simulaitor? how can i impelement a nad gatter in a hdi?

WBahn
Administrator
This post was updated on .
I'm having a very hard time telling exactly what you are asking or trying to do because you have so many typos in your post. I think I get the main gist, but it's impossible to tell for sure. Please proof read and clean up your posts carefully before you post them (and, of course, mistakes will still sneak through, but it will hopefully be minor enough that it will be fairly easy to infer what was meant).

What gate is it you are trying to implement? I have no idea what you mean by a "nad gatter".

When you say you have:

kiohoilgb8 wrote
CHIP t {
    IN a,b;
    OUT out;

    PARTS:

}
Where is that 't' in the first line coming from?

The name of the gate you are implementing needs to go there.

When you have:

PARTS:
    NAND(a=true, b=false)
You are saying that the chip you are making consists of a single Nand gate in which one input is tied permanently HI (true) and the other is tied permanently LO (false), but whose output isn't connected at all. You are also saying that neither of the two chip inputs is connected to anything and neither is the one chip output.

The text gives you an example HDL file for the Xor gate (even though you haven't implemented any of the parts it uses yet, but you can use the built-in parts to get the simulation to run if you want).

Let's make a fictional gate that I'll call a 'Fred' gate. It has three inputs, 'tom', 'sally', and 'mary'. It also has one output, 'henry'.

The logic that we are trying to implement is the following:

tom sally mary henry
  0   0    0     1
  0   0    1     1
  0   1    0     1
  0   1    1     1
  1   0    0     0
  1   0    1     0
  1   1    0     0
  1   1    1     1

Before we do any of the internal implementation, we can set up the basic HDL file as follows:

CHIP Fred {
    IN tom, sally, mary;
    OUT henry;

    PARTS:
    // Put your code here:
}

Do you see how those top three lines define the interface of this part to the rest of the world in terms of the name of the chip and the names of the input and output signals?

Now we can turn our attention to the internal logic.

We know that a Nand gate has the following behavior:

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

Notice that if either input is LO (0), the output will be HI (1) regardless of what the other input happens to be.

Next, notice from the truth table for our 'Fred' gate that the output is HI any time that the 'tom' input is LO. That means that we can use a Nand gate to get a good portion of our desired behavior by connecting one input to 'tom' and using the output for the chip's output ('henry'). But the other input to this Nand gate depends on both of the other two chip inputs ('sally' and 'mary'). So we will need some additional logic that uses 'sally' and 'mary' as inputs and produces a new, purely internal signal (which we will call 'danny'). At this point our (still incomplete) implementation looks like this:

CHIP Fred {
    IN tom, sally, mary;
    OUT henry;

    PARTS:
    // Need something here to use sally and mary to generate danny
    Nand(a = tom, b = danny, out = henry);
}

What does the missing logic need to do? Let's add 'danny' to our truth table and take into account that 'henry' is the Nand of 'tom' and 'danny'.

tom sally mary danny henry
  0   0    0     x     1
  0   0    1     x     1
  0   1    0     x     1
  0   1    1     x     1
  1   0    0     1     0
  1   0    1     1     0
  1   1    0     1     0
  1   1    1     0     1

When 'tom' is LO, we don't care what 'danny' happens to be (indicated by the 'x' in the truth table) because the Nand gate will force 'henry' to be HI. But when 'tom' is HI, we see that we need 'danny' to be the Nand of 'sally' and 'mary'. Thus our final design becomes:

CHIP Fred {
    IN tom, sally, mary;
    OUT henry;

    PARTS:
    Nand(a = sally, b = mary, out = danny);
    Nand(a = tom, b = danny, out = henry);
}

Now, what if the pin names for our 'Fred' gate were the more traditional 'a', 'b', and 'c' for the three inputs and 'out' for the output? Simple -- every place where we have 'tom' we replace it with 'a' and so on. We can name purely internal signals anything we want (other than one of the names used for the chip's input and output. The only internal signal we have is 'danny', so let's replace it with 'd'. That would make our logic design:

CHIP Fred {
    IN a, b, c;
    OUT out;

    PARTS:
    Nand(a = b, b = c, out = d);
    Nand(a = a, b = d, out = out);
}

The fact that our Nand gate has a pin called 'a' and our chip has a signal called 'a' is not an issue. In the pin list for given part, the name on the left of the equals sign is the name of one of that part's pins while the name on the right of the equals sign is the name of one of the signals in the chip's design (either a pin or an internal signal). These are completely separate and distinct things.
Reply | Threaded
Open this post in threaded view
|

Re: How to use the hardware simulaitor? how can i impelement a nad gatter in a hdi?

kiohoilgb8
In reply to this post by kiohoilgb8
Sorry, I think I explained everything wrong. Our uni task is that we use the simulator to make an "xor" circuit and an "and" circuit.

Our professor told us that we should only use nand gates to develop this. And he told us that we do not have to implement the nand gates ourselves, because they are already automatically given by the program. I just do not know how to use the nand gate, which is automatically given by the program.
Reply | Threaded
Open this post in threaded view
|

Re: How to use the hardware simulaitor? how can i impelement a nad gatter in a hdi?

rleininger
I recommend that you refer to the PowerPoint slides provided by the creators of the Nand2Tetris course from their public web site https://www.nand2tetris.org/course which is located here:

https://drive.google.com/file/d/1MY1buFHo_Wx5DPrKhCNSA2cm5ltwFJzM/view

The section you are probably interested in begins at Slide 61.  It describes the methodology for creating an Xor chip in HDL.  Notice that the Xor chip design that is provided here does not use Nand chips, but is built from Not, And, and Or chips.  However, these three chips can be constructed from the built-in Nand chip.

The idea they are promoting is to start by building simple chips from Nand gates and then using those chips to build more complex chips.  Using this technique, all the chips that are built are technically built from Nand gates, even though their HDL files may contain the names of other previously constructed gates.  Hint: Start with the Not gate.


Reply | Threaded
Open this post in threaded view
|

Re: How to use the hardware simulaitor? how can i impelement a nad gatter in a hdi?

WBahn
Administrator
In reply to this post by kiohoilgb8
Look at the 'Fred' gate example I gave. It is constructed using two Nand gates.

If you were to then use a 'Fred' gate in a subsequent design, that design would still qualify as using only Nand gates because the 'Fred' gate is built using only Nand gates. The use of the 'Fred' gate is merely to manage the complexity and control the degree of abstraction -- something which is an explicit goal of the authors.
Reply | Threaded
Open this post in threaded view
|

Re: How to use the hardware simulaitor? how can i impelement a nad gatter in a hdi?

rleininger
Well-said.  The decomposition of a complex problem into simpler and more easily solved sub-problems is a bedrock analytical principle in computer science and just about every other problem-solving field.