Today, I am going to Write about another important topic, needed for learning exploit writing. In this Post, I am going to cover CPU organization topic. In this Topic we will learn about the basic structure, concept, and design of the Central Processing Unit and How its work?
readers, I am trying my best to keep all my posts simple and easy to understand but if anyone feeling anything missing in my post then please comment below.
So, Let's Start
As We know in the computer system, CPU is like heart and brain for Computer. It consists many types of other components also like arthimatic unit, logic unit, control unit, registers, decoders etc. Central Processing Unit also connected with various Input-Output Devices and memories In Simple words, a computer processor is responsible for doing various types of operation in computer architectures. The purpose of CPU is to execute the instruction stored in the main memory.
So, let's Explore More To Get Basic Information How Exactly all instructions perform their operation under the hood.
Basic Diagram Of How CPU Connected with Other Components.
As You Can see Above Central Processing Is Connected With Many External Components Like Memory Unit (RAM, ROM, CACHE), INPUT, OUTPUT, ETC
. In Computer Architecture, All these mentioned units are linked to one another via buses. now, the question arises in our mind, What is Bus? Well, Basically a bus is a set of wires that carry data bits and act as a communication bridge between the processing unit and other peripherals. Why Bus? Because Bus is a fast and safe medium of data transfer from one place to other.
Usually, Bus support 2 types of data transfer. Unidirectional Bus and Bidirectional Bus. Unidirectional refers to One-way Data Transfer and Bidirectional Supports Both Way Data Transfer.
Now, let's Move Ahead And Talk About CPU.
This is the basic diagram of CPU components.
What is Registers?
To Execute an instruction in CPU, registers play very important roles. Registers are used to quickly store, accept and transfer data with lighting fast speed. They are fast because registers are built from the fast multi-ported memory cell. In simple words, as I already told you in my previous posts, that CPU registers comes at the top of the memory hierarchy because registers are the fastest way to manipulate data but they can store very small bits. to perform any operations CPU undergoes with the sequence of operations called instruction cycle. Basically, there are three types of cycles .1. Fetch:
During Fetch Operation, the CPU fetches the instructions to be executed, from main memory and the instruction given by the user.2. Decode:
During Decode Operation, the CPU find out which operation is to be performed to satisfy instruction requirements.3. Execute:
At the End, in execute, operation CPU actually perform all the operations to satisfy the instructions requirements and save the result into the memory and that they are displayed on the screen
Various Types Of Registers (Trying To Explain In Simple Words)
Accumulator Register(AC) :
This register located inside the ALU. Here, ALU stands for Arithmetic and Logistic Unit. Accumulator Register is used for storing data for performing arithmetic operations. In simple words, accumulator registers are used to store initial data, intermediate results and the final results.Memory Buffer Register (MBR):
This register Only holds data or instruction read from memory or to write in memory.Program Counter (PC):
This register is used to point to the next instruction to execute This register is also known as Instruction Pointer.Instruction Register (IR):
After Fetching instructions from main memory, all instruction is stored in this register to perform operations in CPU.
Address Register (AR)
Address Register is used for specifying the addresses of a particular Input-Output device.
Buffer Registers is used to exchange data between Input Output module and the processor.
Data Registers (DR)
A Register used in micro-computer to temporarily store data.
Memory Address Registers (MAR)
This register holds the address of memory where CPU wants to read instruction Or Store instructions.
Special Extra Registers to make CPU more powerful
General purpose registers :
A general purpose register can be used for various functions desired by the processor, like either to contain an operand or an address of an operand for any opcode of an instruction.
Because This Topic is important to let's take deep dive of General Purpose Registers.
Basically, General Purpose Register are also Further Divided into Three Groups
- Data registers,
- Pointer registers,
- Index registers.
Data registers are used for arithmetic, logical, and other operations.
Few Examples Of Data Registers Like
- As 8 Bit Registers
- DH, and
As Their Name Suggesting, This types of register basically used to point any address or location in memory.
- Pointer Register
- Instruction Pointer (IP)
- Stores the offset address of the next instruction to be executed
- Stack Pointer (SP)
- Provides the offset value within the program stack
- Base Pointer (BP)
- Referencing the parameter variables passed to a subroutine
The 32-bit index registers are used for indexed addressing and sometimes used in addition and subtraction.
- Index Registers
- Source Index (SI)
- It is used as source index for string operations.
- Destination Index (DI)
- It is used as destination index for string operations.
Condition Codes Registers
These registers are used to contain various types of the conditions codes during operations, those condition codes indicate specific conditions set by the CPU. These condition codes called flags.
- Overflow Flag (OF)
- It indicates the overflow of a high-order bit (leftmost bit) of data after a signed arithmetic operation.
- Direction Flag (DF)
- It determines left or right direction for moving or comparing string data. When the DF value is 0, the string operation takes left-to-right direction and when the value is set to 1, the string operation takes right-to-left direction.
- Interrupt Flag (IF)
- It determines whether the external interrupts like keyboard entry, etc., are to be ignored or processed. It disables the external interrupt when the value is 0 and enables interrupts when set to 1.
- Trap Flag (TF)
- It allows setting the operation of the processor in single-step mode. The DEBUG program we used sets the trap flag, so we could step through the execution one instruction at a time.
- Sign Flag (SF)
- It shows the sign of the result of an arithmetic operation. This flag is set according to the sign of a data item following the arithmetic operation. The sign is indicated by the high-order of the leftmost bit. A positive result clears the value of SF to 0 and negative result sets it to 1.
- Zero Flag (ZF)
- It indicates the result of an arithmetic or comparison operation. A nonzero result clears the zero flag to 0, and a zero result sets it to 1.
- Auxiliary Carry Flag (AF)
- It contains the carry from bit 3 to bit 4 following an arithmetic operation; used for specialized arithmetic. The AF is set when a 1-byte arithmetic operation causes a carry from bit 3 to bit 4.
- Parity Flag (PF)
- It indicates the total number of 1-bits in the result obtained from an arithmetic operation. An even number of 1-bits clears the parity flag to 0 and an odd number of 1-bits sets the parity flag to 1.
- Carry Flag (CF)
- It contains the carry of 0 or 1 from a high-order bit (leftmost) after an arithmetic operation. It also stores the contents of last bit of a shift or rotates operation.
Status and Control Registers
A status register often known as program status word (PSW) serves the purpose to contain the condition code and other status information. similarly, Interrupt vector register (IV) and Stack Pointer (SP) are the other status and control registers, respectively.
. I think it's enough for Today. so, this post ends here.
I hope you enjoyed it.
Have a nice dayClick Here For Next Part