Skip to main content

DESIGNING A RELAY COMPUTER: The Adding Machine

In a CPU there is circuitry dedicated to do all kinds of arithmetic operations and logical operations on binary numbers. Adders are circuits that reside in this ALU section of the CPU and they, as the name suggests, add numbers.
So, how exactly does a circuit add binary numbers??
As I had previously mentioned in my post talking about number systems, certain properties of numbers remain the same regardless of the base of the number system. So, adding two binary numbers is similar to adding two decimal numbers. Lets first look at how we add decimal numbers.
Suppose we were to add two 3 digit numbers:
To add these two numbers first we add the numbers in the units place.
Upon adding the two numbers we get either a single digit answer or a double digit answer.
If the answer is a single digit it is considered the units digit of the final sum and we add the digits of the next place value.

If the answer is a two digit number the units place of the answer is considered as the units digit of the final sum and the digit in the 10's place is considered as carry.

 The carry is then added with the next stage with the numbers in the 10's place. This process is continued till all the digits have been added.
When adding in binary we follow the same routine.
For example adding 5 and 7 in binary:
The only thing to remember is that in binary 1+1= 10 and 1+1+1= 11......
The rest is the same....
Now, lets try and figure out how to make a circuit that adds. We know for a fact that if we can add two single digit numbers adding 2 double digit numbers is same as doing single digit addition twice.
So, in reality we just need one circuit design that does addition of two single digit numbers.
Hence, we need a circuit that has 2 inputs.
For output we need 2 outputs since our answer may be single digit sum or a single digit sum and carry.
With these things cleared out we can make a table:
Upon close inspection one can realize that the 'S' sum output is the same as an XOR gate output and the 'C' carry output is the same as an AND gate output. So, this circuit can be made using an XOR and an AND gate.
This circuit can now be implemented with relays:
Even though the previous circuit works, it has a major drawback that it uses 4 relays. The relays can be reduced by optimizing the AND gate circuit.
The XOR gate can be optimized as well, reducing the circuit to just two relays (try it if you want ;p).
This adder circuit formed is only good for adding the first two digits though, since for the next place value the sum is calculated by adding 3 inputs X Y and C generated by the previous adder circuit.
Since the above adder only adds two inputs and not the previous carry its called a "Half Adder".
The circuit that also takes a carry input is called a "Full adder".
We can build the full adder using two half adders and an OR gate.
The relay circuit looks like this:
In the circuit there are 2 relay half adders. The carry output of both the adders is OR'ed using just one relay ( another optimization ).
Now, with the help of the Half Adder and the Full Adder we can calculate the sum of 2 binary numbers for any number of digits. for 'N' number of digits we need 1 Half adder and 'N-1' Full adders.
For example, if we were to add two 3 digit numbers:











And that is how you make adding machines.

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...