Hardware Lesson 5:
Processors & Logic
Introduction
The processor is the heart of the computer, but there is something behind all of the parts of a computer that is even more important, and that is digital circuits. These circuits use logic to control how electricity flows through the computer, which can power different components of the computer and move data.
Switches
A switch is a very simple component, but it is essential to computers.- Transistors are used as switches in current computers.
- A switch works similarly to a light switch.
- Turning a light switch on sends current to the bulb, turning the bulb on. If the switch is off no current is sent to the bulb so the bulb will turn off.
- A switch in a computer
is controlled by its input. If there is a current flowing through the input then the output will have a high voltage charge (or a 1 in binary). If there is no current flowing to the input the output will have low voltage (or a 0 in binary). - Switches can be used to control other switches. The chain of switches below would all have an output of 1 if the input for the first switch was 1.

Gates
- Putting a bunch of switches together in a line is pretty useless, but switches can be put together in creative ways to create gates.
- Putting three gates together like the picture below creates something called an AND gate.

The output for an AND gate is only 1 if both of the inputs are 1. This gate is used so often that it is given a special symbol.- Truth tables can be used to determine the outputs of gates. A truth table is a mathematical table used to compute the results of logical expressions.
| Input1 | Input2 | Output |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
- Another common gate is the OR gate.

An OR gate has an output if 1 if one or both of the inputs are 1.- The truth table for an OR gate looks like this:
| Input1 | Input2 | Output |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
The other common gate type is a NOT gate. It simply changes the charge of the input.- A NOT Gate is much more complex than AND and OR gates, but if you want to see its architecture check out the links at the bottom of the lesson.
Binary Addition
- Adding binary numbers is simple:
0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 2...but we only have two numbers in binary. In this case we carry a 1 to another digit resulting in 10.

- The gates we have learned about can be used to add binary numbers. Determining if there is a carried number can be done using an AND gate as seen below.

- This half adder will be used to add two 1-bit binary numbers. Determining the result is a little bit more complex as you can see below.

- This half adder will be used to add two 1-bit binary numbers. Determining the result is a little bit more complex as you can see below.
| Input1 | Input2 | Output |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
- The above set of gates is used so often that it is called an XOR gate or exclusive OR gate. The gate can be seen below joined with the AND gate for the carry part of the half adder.
- The box on the right is used to represent the half adder. X and Y are the inputs, C is the carry out, and S is the sum.

Processor Logic
- Processors use logic. A group of adders called the ALU do most of the mathematical calculations of the computer. Below is a simple example of a processor.

- The address bus sends an address to memory so the memory knows where to write to or read from.
- The data bus sends the data to memory that will be written to memory, or receive data that is read from the memory.
- The boxes marked 3-state are tri-state buffers that can allow multiple inputs to connect to a wire but only one at a time can send a 0 or 1.
- The RD (Read) and WR (Write) lines tell the memory whether to read or write to the address location.
- Registers are used to store charges so they almost work like memory. The address latch works the same way.
- The program counter works the same as registers, but has the extra ability of incrementing by 1 or reseting to 0 when told to do so.
- The instruction decoder tells the CPU what to do.
- Finally, the ALU is an 8-bit adder similar to the half adder we made.
More Information
If you are interested in learning more about processors or logic.
- All About Circuits gives a detailed, and highly technical, explanation of how a NOT gate works.
- Computer Science 231: Computer Architecture I at the University of Illinois is the course this lesson is based off of. The course goes into even more detail on logic and circuits.
- Computer Architecture II is the follow up to the first course at U of I and discusses machine language using the MIPS assembly language.

