CPU Made Simple
What is the CPU (Central Processing Unit)?
The CPU short for “Central Processing Unit” is like the brain of the computer. Once you understand how it works you will understand the computer as well. There are lots of different wires carrying information around the CPU.
In every CPU there is a particular wire that turns on and off at a steady rate to help keep everything in sync. That wire is called the clock and the clock in this simulation (The 6502 CPU) is turning on about twice a second. Modern CPUs are measured in gigahertz Giga meaning billion and hertz meaning times per second. So the clock in modern CPUs turns on several billion times per second that speed is what allows CPUs to do very complicated things very quickly.
However, what the CPU does during each clock tick is actually very simple. The CPU on your computer might be manufactured by a company like Intel or AMD but the type of CPU we are going to look at is called the Scott CPU. The Scott CPU doesn’t actually exist except as a design.
Underneath the CPU you will see a lot of pins sticking out. That allow the CPU to take in information and send it back out. The CPU fits into what is known as the motherboard. The motherboard allows all the components in the computer to connect to each other. On the right of the motherboard is a place for something called RAM. RAM is short for “Random Access Memory” and it just contains all the data that is being processed by the CPU.
How The CPU and RAM Interact?
Image Source: buthowdoitknow.com
RAM consists of a list of addresses and at each of those addresses is a piece of data. The CPU normally requests and processes each piece of data from RAM in order – one after the other. However, if the CPU is instructed to pull data out of order it can do so. That is why it is called Random Access Memory. The data can be accessed randomly if it needs to be, although normally it is accessed in order.
When a computer first starts running a program it sends an address to RAM to begin retrieving that program. The RAM address just consists of a series of ones and zeros representing on and off wires. RAM doesn’t do anything with that address until the CPU also turns on the set or the enable wire.
If the enable wire is turned on, RAM automatically sends whatever piece of data is at that address back to the CPU. That data is then processed by the CPU accordingly. Once the CPU is finished processing that piece of data it then sends another address to RAM, turns on the enable wire and gets the next piece of data from RAM. This process happens over and over again inside the computer.
If the CPU needs to save data to RAM, it outputs an address. Outputs some data and then turns on the set wire. The ram will then overwrite the data at that address with the new data.