What are the basic components of a processor and how do they work?

In summary, a CPU is a chip that does the work of your computer. You can think of it as the brain of your computer. It has a lot of registers which it can use to store data, and it also has a lot of operations which it can use to perform calculations.
  • #1
mr200backstrok
27
0
i want to know how it works, on a really basic scale (like what components do what). The farthest I've read about is on the assembly language level. I want to know how the hardware works.

any ideas?
 
Technology news on Phys.org
  • #2
Indeed, this interests me too. I can't connect the concept of how a transistor behaves with the ability to perform binary arithmetic. I've seen circuit diagrams of logic gates, but I haven't followed them through to see what's actually going on.
 
  • #3
Basically you start off with some logic gates, like the AND, NOT and OR, for example.
Each gate receives one or more binary inputs (each either 0 or 1). The AND outputs a 1 if both its inputs are a 1 and a 0 otherwise. The OR outputs 1 if either input is a 1 and 0 otherwise. The NOT outputs a 1 if the input is 0, and 0 if it is 1.
With these gates you build components for adding numbers. Addition of binary numbers is the same as addition of regular (base 10) numbers, for example 6+2 is, using 16-bit numbers:
Code:
 00000110
+00000010
------------
 00001000
We can implement addition using the basic logic gates, to form an 8-bit adder, which adds two 8-bit numbers. The adder starts at the rightmost bits of both inputs and moves left, computing the sum and any carryovers for the next column, just like we do manually.
Once we have 8-bit adders, or X-bit adders, we can stack them, or cascade them for summing numbers of 16, 32, 64 bits, etc.
With addition implemented you can now think about implementing multiplication, and then division, there are some popular & clever algorithms for doing multiplication and division using basic gates.
Some other operations you might want to do are shifts, i.e. shift all bits right or left:
shift 001 left = 010
So you develop a collection of operations all acting on 1 or more inputs:
Division
Multiplication
Addition
Subtraction
Logical AND
Logical NOT
Logical OR
Logical XOR
Shift Left
Shift Right
...

Then once you have these operations in place you want to use them. So you want to bring inputs in and perform operations on them. The CPU has a number of registers which store inputs and outputs. For bringing in input from main memory and storing it in the registers, so that you perform operations on them, you add an operation from moving bits from main memory into the registers, that's another operation.
Now that we have so many operations, we want to tell the CPU what operation to do. So, we encode the operations in some bit pattern, for example:
0001 Perform NOT
0010 Perform AND
0011 Perform OR
0100 Perform Addition
0101 Perform Subtraction
0110 Perform Multiplication
0111 Perform Division
1000 Move bits from memory into registers
...
...etc

Now, suppose you want the CPU to perform addition of 6 and 2, you pass it in the operation code (0100), the number 6 (0110) and the number 2 (0010), so something like:
0100 0110 0010
Now we can start talking about a sequence of operations:
0100 0110 0010
01010 010 0010
0100 0110 0110
0010 1000 0010
1000 1010 0010
...
This Machine Langauge is hard to work with so we develop assembly languages, which compiles to Machine Language, so for adding two numbers maybe now we can do:
ADD $R1 2
Which adds 2 to the value in register 1 perhaps. This way it's easier to develop computer programs. One other operation we might now be interested in developing is the Jump operation. Which jumps to the Nth operation and continues from there. Maybe the Machine Code for jumping to line 4 is:
1001 0010 0000
and the assembly command is
JMP 4
or
JMP #MyLabel

With jumps we can start developing conditionals, i.e. Jump to this line if A > B (that reminds me, implement CPU support for >, <, ==)
We can also start thinking about loops, i.e. if you reach this line and Y is 0, jump to the line X lines back and repeat.
We reach a point where we think we can do better than assembly, so we develop higher level languages like C, C++ which maybe compile to assembly and then to machine code, or to machine code directly.
Then we use those languages to develop frameworks, such as the Java virtual machine, or the .NET framework, and now the underlying CPU implementation isn't relevant anymore as far as your programming goes.

CPUs also have to implmement caches, because bringing in data from main memory is not as fast as we'd like. These caches cache the data we bring in from memory. There's also internal stuff like the instruction pointer, which points to the next operation to perform. There's also "interrupts" which trigger code routines to run (this way when you plugin a USB device, an interrupt is generated, the CPU runs some code, which the Operating System can recognize and handle for instance).

These are some of the main ideas, but CPU makers are looking for performance, so they implement different kinds of strategies and approaches.
 
  • #5
Great post -Job-! I've been a programmer for a long time but I've had a new desire to get lower and lower into the technology. Thanks for the heads up. Google thinks your explanation is worthy as well.
 
  • #6
There is an excellent book called 'code' by Charles Petzold that explains how computers/binary/etc work for non technical audience.
It's a little basic if you already know assembler but is very well written.
 
  • #7
ok guys my brother in law and i have been having this discusion about how this all works .

i have tried to explain to him how the programs are compiled into binary machine code .
and the machine code is read in the form of electrical current .but in all my research and reading one thing keeps coming to mind,so please correct me if I am wrong.

the way i understand it is this: the processor is not smart,it only gets instructions on what to do from programs through your ram/harddrive in the form of electrical current .

and depending on the rout of the current the cpu will open or close its switches ,thus either rerouting impulse or stopping the flow of impulse.

so is the processor "dumb"? does it really act as a wet brick until it is told what to do in the form of electrical impulse through the binary code?

the way i understand it is the ram reads data from the harddrive ,loads the data ,then outputs the data through a series of electrical "neuro pathways" causing switches or relays to be triggered thus outputing code in the form of current to be redirected to other parts of the system.

please correct me or fill in the gaps for me.
 
  • #8
One thing not mentioned yet is how computers convert instruction opcodes into actual operations. The simplest form of these is probably is to used the opcod to index into a table of "bit per function" values, which was common on 2901 bit sliced based mini-computers. These machines had a limited number of registers (just 4), and limited number of instructions, so an 80 bit value would be large enough to represent all 80 possible instruction combinations possible. The opcode would index into the "bit per function" table, and which bit that was set would enable the circuitry to perform that specific instruction.

A step up from this would be to index into the start of a series of bit per function values, so that a series of operations could be performed, there would need to be a bit value to indicate the end of a series for a particular instruction.

IBM implemented a similar concept with it's "micro-code" handling of 360 machine language opcodes. Depending on the machine the "micro-code" handled all the "native" instructions implemented on the machine, and exception handling and conventional machine language routines were used to handle "native" instructions not implemented on a particular machine.
 
Last edited:

Related to What are the basic components of a processor and how do they work?

What is a processor?

A processor, also known as a central processing unit (CPU), is the brain of a computer. It is responsible for executing instructions and performing calculations necessary for a computer to function.

How does a processor work?

A processor works by receiving instructions from a computer program and then executing them in a specific sequence. It does this by fetching instructions from memory, decoding them, and then carrying out the necessary operations.

What are the components of a processor?

A processor typically consists of an arithmetic logic unit (ALU), control unit, and registers. The ALU is responsible for performing arithmetic and logical operations, the control unit manages the flow of instructions, and registers store data temporarily.

What is clock speed and how does it affect a processor's performance?

Clock speed, measured in gigahertz (GHz), refers to the number of instructions a processor can execute per second. The higher the clock speed, the faster a processor can process instructions. However, other factors such as the processor's architecture also play a role in overall performance.

What is the difference between a single-core and multi-core processor?

A single-core processor has only one core, or processing unit, while a multi-core processor has multiple cores. This means that a multi-core processor can execute multiple instructions simultaneously, resulting in faster processing speeds and better performance for tasks that can be divided into multiple threads.

Similar threads

Replies
8
Views
1K
  • Programming and Computer Science
Replies
25
Views
2K
  • Programming and Computer Science
Replies
17
Views
2K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
20
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Programming and Computer Science
Replies
29
Views
2K
  • Programming and Computer Science
Replies
5
Views
1K
Back
Top