# what is the function of a transistor in a microprocessor?

I do not have any in-depth knowledge of electrical engineering, but I would like to understand the purpose of a transistor in a microprocessor. There's usually some talk of Moore's law and that transistors somehow increase computation speed, but it's not clear to me exactly how these transistors are used. I figure it has something to do with pipelining. For example, when a CPU reads some instruction from memory, how are the operations required for that instruction performed with transistors?

-
transistors make logic gates, these gates are used to make flip flops. Gates are used to make combinations circuits while flip-flops are used to make sequential circuits. These are than used to make the different building blocks of a microprocessor like the ALU and others. –  quantum231 Apr 22 at 14:17

It would be pretty hard to design a modern microcontroller from the transistor level. Transistors are used to make logic gates, as the lowest level building blocks. The most simple gate is the NOT gate, which inverts the input level: a logic 0 becomes a 1, and vice versa. The NOT gate is built with 2 transistors:

The top transistor conducts if its input (the small dot) is low, the bottom transistor (no dot) if its input is high. So if you apply a high input the bottom transistor conducts, acting as a switch, and switch the output Q to Vss (that's your -), or low level. We've inverted the input. Other gates are based on that. Take the NAND gate for instance. It has two or more inputs, and the output is low if all inputs are high. In all other cases the input is high.

This is a 2-input NAND gate, you still can see some of the inverter in it. If both inputs are high the bottom transistors both conduct, and the output is made low through its connection with Vss. If either of the inputs is low at least one of the top transistors conducts and output will be made high through its connection with Vdd (that's your +). We've got a working NAND gate. And so it goes on, we can build an XOR gate using 4 NAND gates, and other more complex logic is built from a combination of building blocks. You need a building block to create a register function: a part which can hold its state, like a memory.

If an instruction wants to read from RAM there's first the instruction decoder. Through a combination of gates it derives a number of signals it needs to execute the instruction. One of those will be to pass the RAM address to be read to the adress bus. (Busses are channels of signals, an address bus for an 8-bit controller may for instance have 16 parallel wires. Busses are a way to get things organized. Without them the controller's design would become very inefficient.) Another signal will activate the RD line (for "read"), which signals the RAM that it should place the data on the databus. Yet another signal will latch that data in a register.

An important thing is timing. You can't latch the data if you haven't given the RAM the time to place it on the bus. All done by the same logic, from building blocks which in turn are built from transistors.

"transistors somehow increase computation speed"

There's nothing else than transistors and their connections. Transistors by themselves won't increase speed. What is true, however, is that technological improvements allow for faster transistors, and faster transistors means faster computation. Some of these improvements are unique technology steps, which you can do only once. But scaling is another factor, and they've kept repeating that since the first ICs were designed. 40 years ago an IC would typically have a 5 to 8 $\mu$m feature size. Today we can produce down to 22nm feature size. (DNA has a 15nm diameter.) With smaller feature size the physical properties of the transistor change allowing it to switch faster. Moore saw in this continuing scaling a trend, which became known as Moore's Law. This can't go on forever without having to take a leap in the used technology. In the 80s it was feared that the then used technology would have its limits at around 200nm to 300nm, because the lithographic process may not work at wavelengths below visible light. But lithography is still the technology used by today's steppers.

-
You've got a minor typo; the NOT gate is described as a NOR gate. –  exscape Jun 2 '12 at 9:52
Oops, well spotted, thanks. Fixed. Adjacent letters on the keyboard? No, that's a poor excuse :-) –  stevenvh Jun 2 '12 at 9:54
@stevenvh I think the last paragraph of your answer has the most value to add –  vicatcu Jun 2 '12 at 23:13
thank you for this very thorough answer! –  mathStudent Jun 3 '12 at 21:25
@davidcary - thanks, I fixed the first one, didn't notice that I did it twice :-) –  stevenvh Jun 4 '12 at 12:45

Without re-writing the book on digital logic and Computer Organization and Design, a transistor implements the function of a switch in the context of microprocessors. They are used to create "switching circuits" typically (e.g. CMOS logic gates). Moore's law is about how many transistors you can fit on a given surface area (i.e. transistor density), and consequently the complexity of logic that you can implement in the hardware (and as an aside the yield that can be achieve in manufacturing).

Since microprocessors are spending most of their time waiting for memory operations (loads and stores) to be completed, a lot of these transistors are being dedicated to high speed memories on the chip called caches that help reduce the frequency of these memory operations actually having to leave the chip. Smaller transistors means you can keep a larger subset of the RAM local to the CPU at any given time. More transistors are also being used to implement fancy predictive circuits, like branch predictors and load value predictors.

Branch predictors and Out of Order Execution units are there to help keep the pipeline full by guessing which way a branch instruction will go based on heuristics associated with the program counter and the recent history of branching results (taken or not).

Load value predictors are there to avoid going to memory to fetch a value (for example assuming a certain "stride" or other heuristic on what the data will be at a certain address based on previous values seen at that address).

Along with these predictive logic circuits comes all the logic circuits that are required to undo and correct computed results when the predictions turn out to have been wrong.

In summary, all these extra transistors are being used to:

1. Avoid instructions from having to leave the chip (i.e. go to RAM) to complete, and
2. Keep the pipeline full or avoid going to RAM by predicting dependency outcomes

One last thing is that they can be used to make your data path wider (i.e. 64-bit processors instead of 32-bit processors).

-
You talk about optimization techniques like caches and pipelining without explaining basic functionality. I think that may be confusing. –  stevenvh Jun 2 '12 at 11:08
@stevenvh sure, but the question he is really asking is not "what is a transistor used for in general", but rather "how does having more transistors make computing faster"... –  vicatcu Jun 2 '12 at 23:10