CPU which is responsible for all the logical operations contains following components:
- A Clock Clock syncs internal operations of components with each other. Each operation involving system bus and CPU is synchronised by a constantly pulsing clock.
- Control Unit Control Unit coordinates the steps involved in Executing instructions.
- Arithmetic Logic Unit ALU performs all the arithmetic operations such as addition,subtraction,division and logical Operations using gates such as AND,NOT,OR.
- Memory Unit MU is where all the memory and storage related functions take place such as moving data from to RAM or hard disk and vice-versa.
- Computer contains a bus which is used to transfer data from one point to another. There are four types of buses.
- Data Bus
- Control Bus Uses Binary Signals to synchronize all the actions between all devices attached to the system bus.
- I/O Bus
- Address Bus The Address Bus holds the address of instructions. (Remember using DCIA (da CIA))
The Basic Time Unit for machine instructions is
clock cycles.The length of clock cycle is the time required to complete on cycle.For example a
1Ghz clock will oscillate for
1 billion times per second. Clock Cycles are calculated by taking
reciprocal of clock speed.
Instruction Execution Cycle
Order of a
Instruction to get executed is a follows:
- First , the instruction itself is fetched from a memory area called
- The instruction is then read by decoding its
binary pattern. The decoded pattern might reveal that
operandsare involved meaning
input valuesare needed , at which point they are fetched from the registers and memory.
- After that, instruction is executed and some flag included
Zero , carry and overflowget updated.
- Finally the result of execution is stored.
So In-short following process happens:
- Fetch An address from Address Bus is used.
- Decode A code or algorithm required for execution is placed in code cache.
- Execute Instruction pointer determines in which order will the instruction be executed.These instructions are decoded and then sent to Control unit which works with ALU and MU in coordination.
Reading From Memory
Reading data from memory involved following steps:
- Place the address of data on address bus.
- Change the value of processors
- Wait one clock cycles for memory chips to respond.
- Copy the data from data bus to destination operand.
Loading and Executing a Program
A utility known as
program loader loads the required program into the memory.First the Operating System locates the file on disk and its actual path, after that execution begins the program is converted into a
process with a process ID or
PID which is used to keep track of the process.
32 bit x86 processors
These include intel as well a AMD processors.
Modes of operation
x86 has 3 modes of operation:
- protected mode
In this mode all the features and instructions are available.Programs are executed in separate memory areas called
segments and programs are not allowed to work outside of their segment.
- Virtual 8086 mode
Virtual 8086 mode is a type of
protected mode where a process can directly execute real-address mode software such as MS-DOS in a
safe environment.If a program crashes or attempts to write data in system memory area it will not affect other programs.
- real-address mode
Real-address mode is a programming environment of early intel processors with extra features such as ability to switch to other modes.This mode is useful when a program needs direct access to system memory and hardware devices.
- system management mode
System Management Mode (SMM) implements functions such as power management and system security.These functions are implemented by processor manufacturers.
Basic Execution Environment
Basic Program Execution Registers
memory locations in CPU designed to be accessed at a higher speed than normal memory transfer. There are
- Eight General Purpose register
- six Segment registers
- A process status flag register
- An instruction or
General Purpose Registers
- General purpose registers are used for arithmetic and data movement.
- EAX is used for multiplication and division.It is called
Extended accumulator register (EAX)
- ECX is used as loop counter.
- ESP addresses data on stack.
- EBP is used by high-level languages to reference function parameters and local variables on the stack.
- In real address mode 16 bit segment registers store memory addresses of memory areas called segments.
- In protected mode segment registers hold pointers to segment descriptive tables.
- Some segments hold program instructions(code) while others hold variables.
Stack Segmentholds local variables and function parameters.
The instruction pointer contains the address of next instruction to be executed.Program can be transferred to a new location if we manipulate the addresses in EIP.
A flag is
set when it is equal to
reset when equal to
The EFLAGS (or just Flags) register consists of individual binary bits that control the operation of the CPU or reflect the outcome of some CPU operation. Some instructions test and manipulate individual processor flags.
Control Flags control CPU operations such as
- causing a break to CPU after every execution
- interrupt when arithmetic flow is detected.
Status flag show the outcome of arithmetic and logical operations.