Play

← fab24hr Blog

Chip basics8 min read

What are logic gates, and how do switches become a chip that computes?

A logic gate is a tiny circuit made of a few transistors: it looks at whether its input wires are 0 or 1 and, by a fixed rule, decides whether its output wire is 0 or 1. The three most basic ones are NOT (a 1 in gives a 0 out, the opposite), AND (1 out only if both inputs are 1) and OR (1 out if either input is 1). When a chip adds, compares numbers or decides what to do next, it does it with huge numbers of logic gates, built up layer upon layer.

To see what a transistor, this tiny switch, looks like, read What is a transistor?. This article starts from the switch and works upward.

What are the 0s and 1s inside a chip?

A 0 or a 1 is a low or high voltage on a wire. Connect the wire to the power supply and its voltage is high: a 1. Connect it to ground (the side at zero volts) and its voltage is low: a 0. What a logic gate does is look at the voltages on its inputs and use switches to connect its output to the power supply or to ground.

Today's chips use two kinds of switch, in pairs. One kind turns on when its gate has a voltage (the input is 1). It's called n-type, and it sits between the output and ground, so its job is to pull the output down to 0. The other kind is the opposite: it turns on when its gate has no voltage (the input is 0). It's called p-type, and it sits between the output and the power supply, so its job is to pull the output up to 1. Pairing them like this is called CMOS (What is CMOS?).

The simplest gate: how does NOT flip things around?

A NOT gate, also called an inverter, has one input and one output, and one pair of switches is enough:

  • Input is 1: the switch to ground turns on and the switch to the power supply turns off. The output is connected to ground: a 0.
  • Input is 0: the switch to ground turns off and the switch to the power supply turns on. The output is connected to the power supply: a 1.

So a switch being on doesn't mean the output is 1. When the input is 1, the switch that's on is the one pulling the output down to 0.

When the gate isn't switching, only one of the two switches is on, so there's no straight path from the power supply to ground, and almost nothing flows except a tiny bit of leakage. That's why CMOS saves power.

What's the difference between switches in series and in parallel?

Picture valves on a water pipe:

  • In series: one pipe with two valves, one after the other. Water gets through only if both are open; if either is shut, it doesn't.
  • In parallel: two pipes side by side, each with its own valve. Open either one and water gets through; only when both are shut does it stop.

Switches work the same way. Two in series make a path only if both are on; two in parallel make a path if either one is on. A logic gate uses these two arrangements to set when its output is connected to ground and when to the power supply.

Switches in series versus in parallel: in series is like one pipe with two valves, one after the other, and water gets through only if both are open; in parallel is like two pipes side by side, each with its own valve, and water gets through if either one is open. Switches work the same way.
A logic gate uses these two arrangements to set when its output is connected to ground and when to the power supply (simplified).

How are NAND and NOR wired, and where do AND and OR come from?

With two inputs, A and B, each input controls one pair of switches, four switches in all:

  • NAND: on the ground side, the two switches are in series; on the power side, the two are in parallel. Only when A and B are both 1 does the path to ground open, so the output is 0. If either one is 0, one of the paths to the power supply is on, so the output is 1. The name means "AND, then flipped".
  • NOR: wired the other way round, in parallel on the ground side and in series on the power side. If either input is 1, the output is pulled down to 0; only when both are 0 is the output 1. The name means "OR, then flipped".

Because a 1 on the input turns on the switch to ground, a single layer wired this way (n-type on the ground side, p-type on the power side) naturally gives the flipped kind. For AND, you add a NOT after a NAND, six switches in all; for OR, you add a NOT after a NOR.

Input AInput BNANDANDNOROR
001010
011001
101001
110101

Why can NAND alone build everything?

It has been proven mathematically: any rule that looks at some 0s and 1s and gives back a 0 or a 1 can be built from NAND gates alone, and the same goes for NOR. For example, a NAND with its two inputs tied together is a NOT. Real chips don't stick to one kind, though; they use whichever gate takes less space or runs faster.

How do logic gates add?

Numbers inside a chip are written in binary, where each digit is only 0 or 1. Just as 9 plus 1 carries in ordinary decimal, 1 plus 1 carries in binary: you write 0 in this digit and carry 1 to the next.

Adding two one-digit numbers has only four cases:

Input AInput BCarryThis digit
0000
0101
1001
1110

The "carry" column is 1 only when both inputs are 1: that's AND. The "this digit" column is 1 only when the two inputs differ: that rule is called XOR (exclusive OR), and four NAND gates can make it. One AND plus one XOR is a one-digit adder, called a half adder.

Add in the carry coming over from the digit to the right as well, and you have a full adder. Put a row of full adders side by side, each passing its carry to the one on its left, and you can add long numbers, just like column addition in school.

What's between an adder and a processor?

Once a chip can add, more is built on top:

  • Comparing: subtract one number from the other and see whether the answer is positive, negative or zero. Inside a chip, subtraction is done with an adder too.
  • Choosing one: one wire acts as the control; if it's 1, the first answer goes through, and if it's 0, the second does. That's made of logic gates too.
  • Deciding what to do next: feed the result of a comparison into the control wire of a chooser, and it decides which part of the program runs next.

At its core, a processor is these circuits that add, compare and choose, plus control circuits that direct them step by step according to each instruction.

While it works, it also has to remember numbers for a moment. Join two NOT gates head to tail in a loop: if the first outputs 1, the second outputs 0, and that 0 keeps the first one at 1. The loop holds itself in place and remembers as long as the power is on. The little cells that hold numbers inside a processor come from this idea (How is memory different from a processor?).

How many logic gates are on a chip, and does anyone draw them one by one?

A two-input NAND takes four transistors and a NOT takes two. A phone chip holds more than ten billion transistors, so even if only part of them go into logic gates, the gates number in the hundreds of millions or more.

Nobody could draw that many by hand. Designers write down what a block of circuitry should do in a hardware description language, and design software turns that into logic gates, places them and wires them up (How are chips designed?).

Why does a gate that's a little slower or leakier matter so much for the whole chip?

Speed: when an input changes, the output takes a tiny moment to follow. Most digital circuits move to a beat like a metronome, called the clock; a phone processor ticks billions of times a second, so one tick lasts less than a billionth of a second. Within one tick, a signal has to pass through a chain of logic gates and finish before the next tick. Make each gate a little slower and the whole chain slows down, so the clock has to slow down too.

Power: every time a gate switches, it fills a little charge in and lets it out again; and while a switch is off, it still lets a tiny bit through, called leakage. One gate's share is too small to matter, but multiplied by billions, it's the power the whole chip uses and the heat it gives off (Why do chips use power?).

In fab24hr

You don't see logic gates in the game. The main story, The life of a chip, follows Glowmere, a fictional hearing-aid chip. Devices like hearing aids usually turn sound into numbers to process it (Analog vs digital chips: what's the difference?), and the circuits that process those numbers are layer upon layer of logic gates.

In chapter 1, "How to Split 12", you're the R&D integration engineer on the R&D line, and you decide how the first 12 wafers are split: apart from the middle case, both kinds of transistor slow, both fast, or one fast and one slow. These skews are called corners. The two kinds are n-type and p-type, the pair of switches inside a logic gate. The "Know a bit more" note on the corner glossary card says the one-fast-one-slow corners are the worry: the two kinds can't keep pace, and the circuit can simply fail. In chapter 10, "Standby Current", you're the test engineer at the test-and-assembly house, and you decide how much current a chip may leak while doing nothing before it's stopped.

The companies, chip, people and numbers in the game are fictional; how logic gates are wired and built up into circuits that compute comes from public, general sources. For other jargon, see Chip fab jargon in plain English.

Where you'll meet it in the gameYou don't see logic gates in the game. In chapter 1 of the main story, The life of a chip, "How to Split 12", you decide how many of the first 12 wafers of the hearing-aid chip Glowmere have both kinds of transistor made fast or slow on purpose, or one fast and one slow. Those two kinds are the pair of switches inside a logic gate.

On fab24hr's R&D line, you decide how many wafers have the two kinds of switch inside every logic gate made fast or slow on purpose, to see whether a hearing-aid chip holds up.

Start at chapter 1, How to Split 12

Teachers: this article can go with "fab24hr in the classroom" in class.

Cite this article"What are logic gates, and how do switches become a chip that computes?" fab24hr, updated . https://fab24hr.com/en/blog/logic-gates/
Free to use in class and for non-commercial teaching: on screen, in handouts, printed for students. Please credit fab24hr. Do not sell it or present it as your own work. Spot a mistake? Report it

More articles

More on this site