Skip to main content

DESIGNING A RELAY COMPUTER: Logic Gates

I remember studying about logic gates for the first time in a computer class in school, AND, NAND, OR, NOR, NOT, XOR gates. It sounded like the stupidest thing I had ever learnt. Added to that it was too easy to even be worth teaching. And why would anyone teach it in a computers course anyway??
Has it got anything to do with computers??
The answer, Yes, it has everything to do with computers. The fact that a digital computer exists is because of logic gates. All of the decisions a computer takes and the tasks a computer does are dependent on logic gates.
It was only in college during my Digital Electronics course did I finally recognize the power of logic gates.

Although its self explanatory, let me first explain what a gate is. A gate is a device that allows an event to happen. It controls when the event happens and for how long that event happens. For eg. the switch acts as a gate for the light bulb since its operation determines when the light is switched ON and for how long does the light stay on. So gates have just two states, they may be ON or OFF (1 or 0 in binary).
Logic gates are devices that switch their gate/output depending on the state of its inputs. The inputs also have only two states ON or OFF.

Logic gates could be of 3 major types:
AND gate
OR gate
NOT gate
together they are also called AOI (And Or Invert) logic.

AND Gate:

AND logic gate has a minimum of two inputs. The gate/output is ON only when all its inputs are ON. This can also be written in the form of a table:
for inputs X and Y and output Z






As can be seen in the above table Z is ON only when both X and Y are ON.

OR Gate:

OR logic gate has a minimum of two inputs as well. The gate/output is ON when either of its inputs is ON. This can also be written in the form of a table:
for inputs X and Y and output Z







As can be seen in the above table Z is ON when either X or Y are ON.

NOT Gate:

NOT logic gate has only one input. The gate/output is ON only when its input is OFF. This can also be written in the form of a table:
for input X and output Z







As can be seen in the above table Z is ON when X is OFF.

These three logic gates can be used to create any other logical operator.

There is one more special logic gate that is worth mentioning because of its uniqueness, even though it can be made using the above mentioned logic gates. 
Its the XOR (eXclusive OR) gate.
For inputs X and Y and output Z the table looks like this:







This gate is interesting since the gate is ON when only one of the two inputs is ON. In other words, its output is OFF when the inputs are the same.

Even though I have explained the logic gates and their "Truth" tables, it still isn't very obvious where one would use them, so let me give you a few simple examples,

EXAMPLE 1:
Suppose you want to design a machine that gives you an umbrella. For this the machine needs 2 inputs. First, if you are going out and second, if it is raining. Now, we make a table for it:

If you replace Yes's and No's with 1's and 0's you will notice its actually an AND gate. So to make this machine we need to make an AND gate.



EXAMPLE 2:
Suppose you want to store water in a tank, with a tap on its side, to use later, but you want a machine that opens the tap when the tank is full so water won't overflow. For this, the machine needs 2 inputs. First, if the tank is full and second, if water is needed for use. Again, making a table for it:

Replacing the Yes's and No's with 1's and 0's we realize we need an OR gate.




EXAMPLE 3:
Suppose we want to make a machine that turns the streetlight ON at night. For this, the machine only needs one input- if there is sunlight or not. Again, making a table:

On replacing Yes's and No's with 1's and 0's we notice its a NOT gate.



Even though I have used very simple examples of machines but, regardless of how complex the machine is, if analyzed properly, one can design the machine using various combinations of this AOI logic.

In the upcoming posts I will be using this concept of logic gates to explain how I designed various parts of my computer. till then...

Got any queries??? 
E-Mail me at: shashwath.sundar@gmail.com

Comments

Popular posts from this blog

DESIGNING A RELAY COMPUTER: Relays

In the previous posts I highlighted the various concepts that are fundamental to designing a computer. Now I think its time to mention the ways of practically applying these concepts to design a computer. The first thing I should highlight is that I will not be using transistors, I'll be using relays. This is due to the fact that its easier to understand how a relay works than to understand how a transistor works. Also, this seems to be the easiest way to understand how computers actually work since we are using mechanical switches instead of solid state switches (transistors). What is a Relay?? Relays are basically electrically controlled switches. Inside a relay is an electromagnet. when the electromagnet is powered, it attracts a metal strip that in turn operates a switch. Most widely available relays are SPDT relays or Single Pole Double Throw relays. In these relays the switch has 3 terminals- Common terminal , NO i.e. normally open terminal and NC i.e. normally ...

Making a URISC Processor: The Idea

So a while back I saw this video on Youtube by "Gary Explains" talking about a "One Instruction Set Computer". For those who do not know, a computer processor does a fixed set of things or follows a fixed set of instructions. Usually modern processors have hundreds of instructions. In the OISC or URISC (Ultimate Reduced Instruction Set Computer) processor the idea is to have one universal instruction that the processor executes that allows the programmer to write any program. The first time I heard of this idea I fell off my chair with excitement (Literally). My mind was really blown by the fact that you could write any program with just one instruction. So after going through what "Gary" on Youtube had to offer... I sat down and tried to come up with a design of this hypothetical processor that executes only one instruction. In the video Gary talked about a processor that executed an instruction called 'SUBLEQ' which simply means, SUB tract and th...

Making a URISC Processor: Micro-Instruction Encoding

 In the last post I described the micro-instructions that are to be executed to execute the SUBNEG instruction. Given below is the table I had posted previously: I realized later that it still might not be entirely clear as to how this was working so I have made a GIF of the same to better explain how the "Subtraction" instruction is executed. Pretty cool huh?.... no??? okay 😢 In The GIF it is assumed that the following data is stored in the RAM: Address    Byte #0000           #32  [B(l)] #0001         #00  [B(h)] #0002         #33  [A(l)] #0003       #00  [A(h)] #0004       #20  [C(l)] #0005       #01  [C(h)] #0032         #07 [Data] #0033       #09 [Data] The next thing we need to do is try to optimize this process. In the above GIF you may or may...