How are individual bits controlled inside of a CPU?

315 views

I know there are transistors to represent 1 and 0 (on and off), and I know that assembly is the lowest human-readable level you can get to telling the CPU exactly what to do. Any and all processes between that are an enigma to me, and I would love to know how it works.

In: 35

10 Answers

Anonymous 0 Comments

In short, logic gates (made of ~~MOFSETs~~ MOSFETs) at the base level manipulate the signals coming in, and the billions of logic gates, all baked into the design of the CPU, controls what occurs and which outputs are “triggered” with more binary.

E: spelling

Anonymous 0 Comments

* 1 and 0 are actually represented by some electric charge stored in something called a register.
* Transistors are the basic building blocks of the components of many computer systems for things including memory registers.
* Transistors can be cleverly arranged to change the voltage they output based on the voltage they receive as input.
* These clever arrangements are called logic gates and have names like AND, OR, NOT, NAND, etc.
* Clever arrangements of *those* allow you to build things like a memory register or a simple device that adds or subtracts two numbers.
* Clever arrangements of *those* allow you to build a CPU etc.
* So as you can see, computers a build on layers and layers of technology that all share a basic trait.
* You take some input, and based on that input, you send some output.

Anonymous 0 Comments

[https://nandgame.com/](https://nandgame.com/)

This is a great interactive game to show how each component leads from one to the next! It’s basically all about finding a pattern to do something slightly more complicated, and using that to do something slightly more complicated, and do that about 3-4 dozen times and you get something pretty dang complicated.

Anonymous 0 Comments

[removed]

Anonymous 0 Comments

You’ve also got resistors on the board which regulate the flow of current and are able to lower the voltage for a circuit.

Anonymous 0 Comments

Transistors are simply switches. They output a high voltage or a low voltage, which we say is a 1 or a 0. We combine transistors in a myriad of interesting ways to make them do specific things. One of the most common things you can make out of a transistor is called a logic gate.

At the lowest level, a logic gate is just a device that changes it’s output based on a logical relationship between its inputs. This relationship, fortunately, is usually easily translated into English. For example, an AND gate has two or more inputs (a, b, … n) and one output. The AND gate works by changing it’s output to a 1 when input ‘a’ is 1, AND input ‘b’ is 1, and so on and so forth. If any input is not 1, the logic isn’t satisfied and the output will be 0. An OR gate works similarly but is constructed slightly differently, such that if input ‘a’ is 1, OR input ‘b’ is 1, then the output is 1.

I can combine logic gates in interesting ways too, and wind up with even more interesting components, like flip-flops and registers. There’s different kinds of both of those things, but one of the main additions to these components that isn’t present in simpler devices is what’s called a clock signal.

If I have an AND gate, and I make one input a 1, then the other, then some small amount of time will pass while the logic gate works and the output changes to one. This time is very small, but what’s more important is that it might not be exactly the same from one logic gate to the next. If don’t know how long to wait to let the logic gate do its thing, I might look at the output before it’s finished, and the output I get might not be accurate. The clock signal solves this problem. Basically, things with clock signals only read outputs, or change inputs, once a clock signal is received.

Now I have everything I need to make a computer. I have data in the form of 1’s and 0’s, and I can use logic gates to do some simple operations and draw conclusions about that data. By using clock signals, I can synchronize lots of different logic gates, and make sure everything is accurate.

When a computer program runs, it translates what we want into more and more basic instructions to the computer, ultimately breaking everything down to one of a small set of very simple operations like adding two numbers, or moving a piece of information from one place to the other. So, a clock pulse may copy some data in memory into a register, while the next clock pulse adds that data to the data in another register, and the next clock pulse stores the result in a new spot on memory, and so on and so forth. This happens billions of times a second. Some of the processing can be offloaded to other forms of hardware, and the operating system is partially responsible for determining what is the most efficient way to handle it, but at its core everything you can do on a computer boils down to taking an input, storing it somewhere, doing something to it, and outputting it somewhere else.

Anonymous 0 Comments

You should think of the internals as “gates” more than 0s and 1s. That’s something humans see and think to better understand this, but what is inside the CPU is all electrical signals that are controlled using gates. There are many many sections to a CPU internally – in particular modern CPUs are quite complex. Each section is a “simple” electronic circuit controlled by an input gate. For instance there are parts of a CPU that hold values (registers), and another part that does arithmetic. By setting the gate to read from a register and another that tells the ALU to add that to a value in the ALU, two control signals are sent to the gates of these items, “turning them on” while keeping the rest off. This is extremely simplified – watch videos, read books, take a free course to get the details.

Machine code (assembler is for humans – you translate that into machine code using a computer we often call “an assembler”) basically represents patterns that turn these switches on/off. So a “value” (op-code) is just a set of bits, which will turn on/off sections of the CPU which causes it to do something.

It doesn’t know anything. Electricity flows through these gates and we have made software that creates “human output” from these electrical signals that look like numbers, letters or graphical interfaces. The CPU has no idea it’s doing this. It’s just electricity.

The basic building blocks are gates. Yes, transistors are used to build gates but it’s not “one transistor one value”. It’s quite a bit more complex, so it’s more correct to talk about circuits.

As you can see, the instructions at this level are very simple when looked at this way. Modern processors have complex instructions, or you can stick to the risc processors and each instruction is extremely simple but very fast to execute. It’s “load this number”, “add 5 to register A”, “jump to address X if value is 0” – very very simple stuff, and a lot of bit magic (algorithms).

Anonymous 0 Comments

Others have answered your question adequately, so I’m just going to copy paste something I told someone a few days ago about a similar question:

>If you are a fan of this subject and would like a deeper understanding of exactly how a computer operates, I’d recommend a game on steam called Turing Complete. You literally build everything yourself. They start you out with 1 single logic gate, the nand gate. Then the game prompts you to create other gates that have a specific function, but they are only made from the nand gate or from the gates you yourself created with the nand gate. It keeps asking you to do increasingly more complex things until you literally build and wire a turing complete computer from just nand gates. If you’re determined, a person with 0 computer science knowledge can learn to build a computer from scratch. The game doesn’t tell you how any of it works, it makes you figure it out with some helpful hints. This way you won’t just have basic knowledge, but also the understanding of the knowledge to back it up. You will 100% understand how a computer calculates based on instruction, because you will be building the hardware architecture yourself, and writing the assembly code that makes it function.

Change “you will 100% understand how a computer calculates on instruction” to “you will 100% understand how individual bits are controlled”. [Nand gate is just a specific arrangement of transistors.](https://mathcenter.oxford.emory.edu/site/cs170/nandFromTransistors/)

Anonymous 0 Comments

When the data is loaded into RAM, each bit has its own pin. When the computer wants to run an operation, it takes the value from each pin and runs then through a circuit in the processor(to add, subtract, multiply, or divide, or any logic operation) and gers a new set of bits it can put onto new pins (or the same pins). 8GB of RAM is 2^26 pins, and each pin can hold 1 bit. If the pin has a voltage, its a 1, and if it doesn’t, it’s a 0. When they are stored on a hard drive, they are either just a small magentic field (hard disk) or by encoded on some flash memory (solid state drive)

Anonymous 0 Comments

A CPU is a machine. The purpose of the machine is to read instructions from memory and then do what they say. Some people have the idea that machine code instructions directly control the CPU or force it to do things. This is wrong – the CPU is voluntarily doing what the machine code instructions tell it because that’s what it’s designed to do.

It’s easiest to study an old 8-bit CPU like you might’ve found in a Commodore 64. Modern ones have too much going on and they do too many things at the same time. The CPU has a few main sections. It has the control unit, which connects to all the other parts of the CPU and sends them signals making them do the right things at the right times. It has the ALU, which is the part that does the calculations, under the control of the control unit. And it has the register file, which stores numbers temporarily.

I suppose the control unit is the part that interests you. It’s wired to do a loop like: connect program counter register to address bus, send memory read signal, connect data bus to instruction register, and then the rest of the loop depends on what the instruction in the instruction register is, and then it goes back to the beginning. When I say “it connects the program counter register to the address bus” I actually mean “it sends out a signal to the place where the program counter register connects to the address bus, telling that connection to activate” because the control unit is just controlling the rest. The loop is part of the control unit though.

An example instruction to add two registers might have the following steps. Everything in the same number happens at the same time, and then the next number happens in the next clock cycle. Each thing that happens is actually just sending a signal to the part that makes it happen.

1. Read program counter register onto address bus. Read memory. Write instruction register from data bus.
2. Read register 5 onto data bus. Write ALU left register from data bus.
3. Read register 6 onto data bus. Write ALU right register from data bus.
4. Tell the ALU to add, putting the result on the data bus. Write register 6 from the data bus.

The CPU designers hard-wired it so things happen in this order.