Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How can I make an IF from gates?

Status
Not open for further replies.

Alex101

New Member
So I hear you can apparently make anything from NAND gates (and, or, xor, etc..) and apparently everything in computing relies on reading and writing values (touring machine). And so I want to create my very own computer (from scratch) using only NAND gates (and yes I realize it would be a very crappy computer).

I can't figure out how to make an 'IF' out of these logic gates though.

I know how to make a loop circuit out of NANDS to store single bit values, and return values, and re-write values, but I don't know how to set a value 'IF' something else equals '0' or '1'. For example...

IF (x equals 1) then (do something) etc....

How can I do something like this out of standard logic gates?

Thanks,
Alex.
 
Last edited:
Look at the following NAND setups:
**broken link removed**

It explains how to make many different logic gates out of NAND's, but does not explain how to create an 'IF' statement out of NAND (or other logic gates).

I'm not really sure what a 'mux' is, but I would presume it's made from logic gates (such as 'and', 'or', 'not', xor' etc.). I am not interested in 'mux', but rather, I am interested in how it works (what logic gates are required and how they should be set up in order to recreate the same effect), assuming that 'mux' is the equivalent to an 'if' circuit.
 
Last edited:
Look at the following NAND setups:
**broken link removed**

It explains how to make many different logic gates out of NAND's, but does not explain how to create an 'IF' statement out of NAND (or other logic gates).

I'm not really sure what a 'mux' is, but I would presume it's made from logic gates (such as 'and', 'or', 'not', xor' etc.). I am not interested in 'mux', but rather, I am interested in how it works (what logic gates are required and how they should be set up in order to recreate the same effect), assuming that 'mux' is the equivalent to an 'if' circuit.
multiplexer/demultiplexer ... encoder/decoder ...

In assembly there is no "if", there are processor flags and branches that are either taken or not depending on the state of the flags. you could think of a decoder as a switch statement, the simplest of which would be and "if".
 
Last edited:
What I don't understand, is how can a modern computer do so many different tasks?

I can ask a computer to compare any values I want, as many as I want, and have it do anything I want. How can this be possible without having to set up every single possible circuit to do that?

If what you're saying is true, then wouldn't I need a multiplexer hooked up to every single bit of memory in the computer? What if I wanted to do thousands of 'IF' statements all at the same time in one statement?

I can understand how a person can make a specific circuit that does a specific task, but how can you make a circuit that allows you to do any task?

For example, imagine I have 5 memory slots, each storing 1 bit, made from SR Latches.
How could I write a circuit (using only logic gates) that can:

p1) Select any (one) of the 5 memory slots. This will be called Mem_A.
p2) Ask if Mem_A is equal to (a choice of) '0' or '1'.
p3) If (p2) returns true, then select any (one) of the 5 memory slots. This will be called Mem_B.
p4) Have Mem_B set to either (a choice of) '0' or '1' (only if p2 was true)

And with the same circuit, I should be able to do TWO, or THREE IF statements at the same time, and/or affect more than just one memory slot as a result. How can you make a circuit with such flexibility, to the point that you could make a simple computer out of it that will perform any task?

?
 
Last edited:
IF (x equals 1) then (do something) etc....
How can I do something like this out of standard logic gates?
You can easily make a 1 bit IF gate. It is called an XOR gate. ;)
 
What I don't understand, is how can a modern computer do so many different tasks?

Because a computer is a system comprised of circuits and programming. Provide enough circuits so that the programming can make up the difference. And still, the computer sitting there doesn't do a whole lot of good until an idea or thought is impressed upon it, by its user.

There are no IF gates because determining IF is way too specific. So, build a circuit to decide IF. For example:

1) Take a 4bit magnitude comparator, say a 74HC85. It can compare two 4bit values and provide one of three outputs. Look at its circuit, it's built out of NOTs, NANDs, NORs, and ANDs. And yes, you can build the whole thing out of NANDs. But it's the circuit that performs the IF function.

2) An XOR gate (74HC86, say) is a more fundamental implementation: compare two bits and provide a high output IF one and only one input is high (or low). It is built out of two ANDs, one NOR, and five NOTs. You can build this all out of NANDs too. Again, it's a circuit that decides IF.

The key is not to build everything that can be built, but only what's needed. After that, thoughts, ideas, and software all take their place.
 
Maybe this VHDL example might help.


Typical Combinational Components
[SIZE=-1](ESD Chapter 2: Figure 2.5)[/SIZE]
[SIZE=-1]The following behavior style codes demonstrate the concurrent and sequential capabilities of VHDL. The concurrent statements are written within the body of an architecture. They include concurrent signal assignment, concurrent process and component instantiations (port map statement). Sequential statements are written within a process statement, function or procedure. Sequential statement include case statement, if-then-else statement and loop statement.[/SIZE]
[SIZE=-2]Multiplexor[/SIZE][SIZE=-2]Behavior [/SIZE]

The link for above source.
 
Last edited:
IF is a BASIC condition statement. I can't think of any machine to act IF a condition is true or false ( maybe a vending machine ( if all coins in slot, dispense product when button is pushed)).
IF I can decipher this post...
 
It depends on what you want to do with the IF.

If all you're doing is setting outputs, good old Boolean logic will do the trick. For example, the VHDL logic
Code:
if x = '1' then
  y <= a and b;
else
  y <= c or d;
end if;
translates to

y <= (x and a and b) or ((not x) and (c or d));

On the other hand, if you're trying to control a sequence, you will need something more complex - such as a state machine, which requires gates, registers, and clocking.
 
What I don't understand, is how can a modern computer do so many different tasks?

I can ask a computer to compare any values I want, as many as I want, and have it do anything I want. How can this be possible without having to set up every single possible circuit to do that?

If what you're saying is true, then wouldn't I need a multiplexer hooked up to every single bit of memory in the computer? What if I wanted to do thousands of 'IF' statements all at the same time in one statement?

I can understand how a person can make a specific circuit that does a specific task, but how can you make a circuit that allows you to do any task?

For example, imagine I have 5 memory slots, each storing 1 bit, made from SR Latches.
How could I write a circuit (using only logic gates) that can:

p1) Select any (one) of the 5 memory slots. This will be called Mem_A.
p2) Ask if Mem_A is equal to (a choice of) '0' or '1'.
p3) If (p2) returns true, then select any (one) of the 5 memory slots. This will be called Mem_B.
p4) Have Mem_B set to either (a choice of) '0' or '1' (only if p2 was true)

And with the same circuit, I should be able to do TWO, or THREE IF statements at the same time, and/or affect more than just one memory slot as a result. How can you make a circuit with such flexibility, to the point that you could make a simple computer out of it that will perform any task?

?

Not sure it will help your thinking, but a computer system (hardware and software) solves a specific problem by building a sequence of small steps to reach the solution, using a software program and the basic capablities of the computer hardware.

While you seem to understand that most any logic equation can be built with basic NAND gates, then you should also be able to understand that a computer's hardware has a limited set of basic instructions if can performed. Think of an instruction as a kind of logic gate. However the programming can using just those basic instructions and solve near any program that can be expressed in the software. Because it's so fast even a 1,000 step program to solve say a square root will appear to happen all at once, but in fact lots of baby step using just the built in instruction set of the processor. To completely understand a computer is to understand each and every one of it's instructions.

Make sense?
 
Alex101: since 2008,how have you got on with your computer-from-scratch project? Your initial "IF" question has also intrigued me.
 
Hy geoge365,

Welcome to ETO.

This is an intriguing topic- how could you possibly make a computer out of simple NAND gates- but it would be better to start a new thread and by all means refer back to this old thread.

Also, care to put your location in your posting window on the left.

spec
 
Hi

AND statement:
Var A
Var B
Var C
If A=1 AND B=1 Then C=1

AND gate:
Input = A
Input = B
Output = C
If A=1 AND B=1 Then C=1 OR
If A=0 AND B=1 Then C=0 OR
If A=1 AND B=0 Then C=0 OR
If A=0 AND B=0 Then C=0

NOT statement:
Var C
Var D
If C=1 then D=0

NOT gate (Inverter):
Input = C
Output = D
If C=1 then D=0 OR
If C=0 then D=1
 
Alex101: since 2008,how have you got on with your computer-from-scratch project?


PLEASE BE AWARE

Alex101 has not been here since December 2008

JimB
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top