На информационном ресурсе применяются рекомендательные технологии (информационные технологии предоставления информации на основе сбора, систематизации и анализа сведений, относящихся к предпочтениям пользователей сети "Интернет", находящихся на территории Российской Федерации)

Feedbox

12 подписчиков

HTG Explains: How Does a CPU Actually Work?

Source: How-To Geek

Most things in a computer are relatively simple to understand: the RAM, the storage, the peripherals, and the software all work together to make a computer function. But the heart of your system, the CPU, seems like magic even to many tech people. Here, we’ll do our best to break it down.

Most of the research for this article comes from “But How Do It Know?” by J. Clark Scott. It’s a fantastic read, goes into much more depth than this article will, and is well worth the couple bucks on Amazon.

One note before we begin: modern CPUs are orders of magnitude more complex than what we’re outlining here. It’s nearly impossible for one person to understand every nuance of a chip with over a billion transistors. However, the basic principles of how it all fits together remain the same, and understanding the basics will give you a better understanding of modern systems.

Starting Small

Computers operate in binary. They only understand two states: on and off. To perform calculations in binary, they use what’s called a transistor. The transistor only allows the source current to flow through it to the drain if there is current across the gate. Essentially, this forms a binary switch, which cuts the wire off depending on a second input signal.

Modern computers use billions of transistors to perform calculations, but at the lowest levels, you only need a handful to form the most basic components, known as gates.

Logic Gates

Stack a few transistors properly, and you have what’s known as a logic gate. Logic gates take two binary inputs, perform an operation on them, and return an output. The OR gate, for example, returns true if either of the inputs is true. The AND gate checks if both inputs are true, XOR checks if only one of the inputs are true, and the N-variants (NOR, NAND, and XNOR) are inverted versions of their base gates.

Doing Math With Gates

With just two gates you can do basic binary addition. This diagram above shows a half adder, created using Logicly, a free online playground for logic gates. The XOR gate here will turn on if just one of the inputs is on, but not both. The AND gate will turn on if both inputs are on, but stay off if there’s no input. So if both are on, the XOR stays off, and the AND gate turns on, coming to the correct answer of two:

This gives us a simple setup with three distinct outputs: zero, one, and two. But one bit can’t store anything higher than 1, and this machine isn’t too useful as it only solves one of the simplest math problems possible. But this is only a half adder, and if you connect two of them with another input, you get a full adder:

The full adder has three inputs—the two numbers to add, and a “carry.” The carry is used when the final number exceeds what can be stored in a single bit. Full adders will be linked in a chain, and the carry is passed from one adder to the next. The carry is added to the result of the XOR gate in the first half adder, and there’s an extra OR gate to handle both cases when the so that would need to be on.

When both inputs are on, the carry turns on, and sends it to the next full adder in the chain:

And this is about as complex as addition gets. Moving up to more bits essentially just means more full adders in a longer chain.

Most other math operations can be done with addition; multiplication is just repeated addition, subtraction can be done with some fancy bit inversion, and division is just…

Click here to read more

The post HTG Explains: How Does a CPU Actually Work? appeared first on FeedBox.

Ссылка на первоисточник
наверх