HACKER Q&A
📣 krishadi

How are billions of transistors controlled?


It is easier to imagine, how transistors in the orders of 10s/100s are controlled by design, when they are all individually soldered/wired. The outcomes are predictable/known.

But, is it the same with microchips with billions of transistors? They are not individually soldered, and I would assume a small percentage of them don't work. How do these work? Are they programmed to work probabilistically? It's unfathomable how complex these are, but how the output from them are so controlled.

I am not from this field, and I have not studied about them more than what I was taught in school in my teens. A google search didn't bring up any helpful results, possibly because I didn't type in the right combination of words. All explanations of these are at the individual component level, -> a single transistor, 1s and 0s, and so on.

How are machine code written for these? Do they track and control the values of individual transistors? And, how is then the assembly language written to translate this to machine code?


  👤 mikewarot Accepted Answer ✓
Don't think of it as billions of pieces each added one at a time, think of it as teeth in a comb, all made at once, in parallel.

Either the whole part works properly (during testing), or, if only a few cores work, the defective portions are disabled permanently, or if none work, it is thrown away. Typical yields for a given silicon production line start at a few percent, and go up towards 100% as much as the process improvement allows.


👤 _Microft
Have a look at https://www.righto.com/

This is the blog of Ken Shirriff (HN user: kens) who is reverse engineering an 8086 processor. You might find answers to some of your questions there.



👤 pfg_
I don't know much either but here's my understanding:

Transistors at that scale aren't placed individually - masks are used on different layers of material directly and it's a chemical process

> I would assume a small percentage of them don't work

Designs are built with tolerances so that small printing differences shouldn't make bad connections and break the chip, and then chips are rigerously tested so that sections with bad connections are either turned off (eg storage devices can be sold as lower capacity if one section is failing), or the chip is unusable

> How are machine code written for these? Do they track and control the values of individual transistors? And, how is then the assembly language written to translate this to machine code?

Machine code doesn't know anything about transistors - the transistors are combined to build a very complicated logic gate. Machine code are inputs to that logic gate that tell it how to control the output

A transistor is a logic gate, either a 'nand' or a 'nor' based on the type (kinda but it's a bit different because it controls if one wire can connect through). You can combine lots of logic gates to make for example an adder. Give it two binary numbers as input and it produces an output.

CPUs are very complicated logic gates, but they're just logic gates. They take input as a bunch of 1s and 0s and produce output. Here's an example of how a simple CPU could work:

As input, it takes:

- some register values. for example, a program counter and three registers r1 r2 r3

- a value that was read from memory

As output, it emits:

- new register values. These are routed back in to the input so they can be used next cycle

- an address to read memory from

Looking at a simple program:

- load 100, r1 - load 200, r2 - add r1, r2, r3

here is how this cpu would execute it:

The program is stored in memory. Let's say it's at 0x00

The cpu starts by reading address 0x00

Next cycle, data is returned from the memory. An instruction 'load 100, r1'

The cpu is a big logic gate - it takes this input: - program counter: 0x00, r1: 0, r2: 0, r3: 0 - memory value: 'load 100, r1'

And it produces output:

- program counter: 0x01, r1: 100, r2: 0, r3: 0 - read memory at: 0x01

Internally, using logic gates it determined that the instruction was 'load' and it outputted the value into the right register, all with a big set of logic gates. It also increased the program counter to know what instruction to read next, and outputted 0x01 as a read address to get the next instruction from memory

The next cycle, it gets this input.

- pc: 0x01, r1: 100, r2: 0, r3: 0 - memory value: 'load 200, r2'

And produces output:

- pc: 0x02, r1: 100, r2: 200, r3: 0 - read memory at: 0x02

The cpu is just a logic gate, so it has no retained knowledge, it only produces output based o its input. Real cpus can have internal state because latches can be made out of transistors too.

Next cycle:

- pc: 0x02, r1: 100, r2: 200, r3: 0 - memory value: 'add r1, r2, r3'

And produces output:

- pc: 0x03, r1: 100, r2: 200, r3: 300 - read memory at: 0x03

Real CPUs are much more complicated and keep lots of internal state and often even run their own internal machine code that they use to translate your code into stuff that's easier for it to understand

I hope this helps as a starting point to know what to look into