How are electrons moved in processors/CPU?

cpuhardware

During our class, he posed the question 'How are electrons moved by code' for our own reflection, the question seems to be vague but I assumed how are electrons moved in a processor/CPU since we were in a computing class. I know that it moves because of conductivity but what does a code have to do with it? So for about half an hour I came to a conclusion that its moved by the code THROUGH the usage of different logic gates. I have searched the net high and low and could not verify my conclusion? Am I right ? If not can you tell me how? THANKS any help would be great!

Best Answer

The symbol below represents a transistor, the fundamental element of any modern computing device. It acts as a switch; current (the movement of electrons) flows from the bottom wire to the top wire when a voltage is applied to the left wire.

enter image description here

Logic gates are created by combining transistors in various combinations. For example, the following circuit implements a NAND gate. A NAND gate is a logic gate that produces a non-zero voltage at its output (Q) only when the voltage at its two inputs (A and B) is zero.

enter image description here

In this circuit, the output indicated by AB (with a bar over it) is held high by resistor R1. When a voltage is applied to both inputs A and B, it switches on both transistors, shorting AB to ground (zero).

Here is the symbol for a NAND gate:

Logic gates can be combined to produce circuits that perform useful work. This circuit adds two bits; it's called a half-adder:

enter image description here

And this is a full adder:

enter image description here

Full-Adders can be combined to support multiple bits. This circuit is capable of adding two four-bit numbers:

enter image description here

With a bit of imagination, you can see how this could be extended to numbers of any arbitrary size, including a 32 bit or 64 bit addition operation.

Each operation so created with logic gates is mapped in the processor to a number called an opcode that the processor recognizes as the number corresponding to that operation. On an Intel processor, the opcode

5  id

maps to this assembly instruction:

add     eax

Which is used in this assembly code:

    push    rbp
    mov     rbp, rsp
    mov     DWORD PTR [rbp-4], edi
    mov     eax, DWORD PTR [rbp-4]
    add     eax, eax
    pop     rbp
    ret

Which corresponds to this C code:

int twice(int num) {
    return num + num;
}

So as you can see, the instructions that you write in your software translate into machine instructions that map onto logic gates that are created from transistors that act as switching devices, precisely directing the flow of electrons to produce a specific result.


Disclaimer for the pedants: This is just an illustration. It is not meant to describe precisely what takes place in a given processor, but rather to illustrate the concept of mapping machine instructions to actual circuitry for educational purposes only. Don't drive or operate heavy machinery while reading this post.

Related Topic