Sunday, 11 February 2018

How CPU works

A computer is a electronic device which processes the data and executes instructions, Every modern day computer has a processor, primary memory, secondary memory, Input and Output Devices.
The processor is the brain of the computer, it is the place where all the instructions gets executed.

For the processor, everything is 0's and 1's,all the inputs and  outputs are suitable combinations of 0's and 1's. The processor have the suitable electronic circuits to process these 0's and 1's. Let's say we type word  "A"  in the keyboard, the letter  'A' will have suitable ASCII value  "044", similarly every  alphabet has suitable ASCII value which will be converted to corresponding  binary value for processing. For the output let's take Color "Red" it has suitable Hex value  #ff0000, which can be converted to binary  Now let us see how CPU process these 0's and 1's.

 The processor has Arithmetic and Logic circuits, Control circuits,  Memory registers and buses for transfer of the data. Consider it as a artificial brain, where the  registers contains information  for processing, The arithmetic and Logic circuit  performs Arithmetic and Logical operations. The control circuit controls the execution of instructions,  The buses is similar to nerves of human body which is used to transfer the data within processor and between processor and memory,  I/0 devices.

Arithmetic and Logic Circuit

The Arithmetic and Logic circuit is made of circuit like adder,subtractor  and other digital logic circuits. These digital logic circuits are made up of logical gates like AND,OR,NOR,NOT,NAND,XOR,XNOR. These logical gates is made up  of transistors. The Transistor is simple electronic device which has three terminals, namely Base, Emitter and Collector. Based on the Base Voltage,The collector-Emittor Voltage can be controlled.This circuit is called Transistor as switch. This forms the base for all the logical circuits to work. The Processor is made up of millions and millions of transistor.

CPU Registers

The processor register is one of the smallest set of data holding places inside the CPU, The registers hold the instructions, data address other data fields. The 32 bit execution or 64 bit execution depends on the size of the processing registers.

Control Circuit


The speed of the processor depends on the control circuit which  triggers the processors, this speed is called clock speed, for a 1.7 GHz processor, the speed is 1700000000 cycles per seconds, ie( one billion, seven hundred million cycles per second), this means the CPU processes more than 1 billion instructions per second,  this makes the computer incredibly  fast and multitasking. 

Memory and I/O Operation

The memory inside the processor cannot store lots of data, so there is need for the external memory, this is where the RAM,ROM comes in to place, The ROM is Read Only Memory where the operations like BIOS(Basic Input/Output System) initializing the hardware while boot-up are done. The data inside the ROM is non-volatile. The RAM is another  primary memory for the processor, All the data during program execution is stored in the RAM, the Processor reads data from the RAM and processes it.The data inside the RAM is volatile,after execution from the CPU the OS releases the memory.

For Reading the I/O devices the suitable device drivers is needed for communication between the I/O device and the processor. The device driver raises a suitable interrupt for reading the data from the input device and based on the the processor reads the data, there are specified registers allocated for Input and output operations.

CPU Bus


  The CPU has three types of bus namely Data bus, Address bus and control bus, The address bus is unidirectional bus where the CPU writes the memory address in which the data needed to be read/write. The data bus is used to transfer the data between memory,I/O devices and CPU. It's is bidirectional bus, the data flows to and from the CPU. the control bus carries commands from the CPU and returns status signals from the devices. If the appropriate device is read or write the corresponding  control bus will be active.

The block diagram summarizes  the working of CPU.


Image result for how cpu works



In recent years there are many advanced multi core processors, they have more than one processing unit for processing, which makes the computer extremely fast and efficient.


 Now processor need someone to organize all the things properly and utilize it properly, this role is done by a software called operating System, the main task of the operating system is to manage the CPU resources, allocating memory, it's like the bridge to reach the CPU. The operating system itself resides inside the main memory and performs all these operations. Without Operating system the CPU will not know what to do.

Anyone could wonder, how even a single core processor could able to do many things  in parallel. One may use MS word while playing music in the background, this is taken care by operating system, the OS maintaines queue of tasks that needed to be executed,based the task queue it swiches the execution of task frequently it will look like all the process is running in parallel. This switching is done in nano seconds. There are many scheduler algorithms OS uses for the scheduling of tasks.


This is the basic introduction of how CPU works, there is lot more to learn and know.

Thanks,
Aravind


No comments:

Post a Comment