CSIT215 - Lecture 4
CSIT215 - Lecture 4
+
Lecture - 04
Structure and Function of Central Processing Unit,
Instruction Cycle
+ 2
Processor Organization
Processor Requirements:
Fetch instruction
The processor reads an instruction from memory (register, cache, main memory)
Interpret instruction
The instruction is decoded to determine what action is required
Fetch data
The execution of an instruction may require reading data from memory or an I/O module
Process data
The execution of an instruction may require performing some arithmetic or logical operation on data
Write data
The results of an execution may require writing data to memory or an I/O module
In order to do these things the processor needs to store some data temporarily and therefore needs a small
internal memory
CPU With the System Bus
3
CPU Internal Structure 4
+ 5
Register Organization
Within the processor there is a set of registers that function as a level of
memory above main memory and cache in the hierarchy
Categories:
• General purpose
Referenced by means of the • Can be assigned to a variety of functions by the
machine language that the programmer
• Data
processor executes • May be used only to hold data and cannot be
employed in the calculation of an operand address
• Address
• May be somewhat general purpose or may be
devoted to a particular addressing mode
• Examples: segment pointers, index registers,
stack pointer
• Condition codes
• Also referred to as flags
• Bits set by the processor hardware as the result of
operations
+ 7
Example
Microprocessor
Register Organizations
10
The 8086 has 1Mbyte address space, but not all is active at one time
The 1Mbyte of memory is partitioned into segments
One segment represents an independently addressable memory
locations of 64K consecutive bytes (64Kbytes per segment)
Each segment is assigned a base address (starting address)
Only 4 segments are active at one time: code segment, stack segment,
data segment, extra segment
The segments that are active are identified by the values of four segment
registers:
CS, SS, DS and ES
+ Example – Intel 8086 (Register Organizations) 18
Code
segment
Stack
segment
CS
SS
Data
DS
segment
ES
Extra
8088/8086
segment
FFFFFH
+ Example – Intel 8086 (Register Organizations) (4) 19
00000H
A
B
CS
C
SS
D
DS
E
ES
F
G
H
I
J
K
FFFFFH
Example – Intel 8086 (Register Organizations) 21
One restriction of the segment base address: only the upper 4 hexadecimal
digit of the address can be changed (these 4 digits are the values inside the
segment registers)
E.g. Determine the segment base addresses of the code segment, data
segment, extra segment and stack segment if the contents of the segment
registers are as shown below.
CS 0120H
DS 0250H
ES 0500H
SS 2020H
+ Example – Intel 8086 (Register Organizations) (7) 22
Instruction Pointer
Instruction Pointer (IP) is a 16-bit register that identifies the location of the next
instruction to be fetched from the current code segment (depends on CS)
It contains the offset of the next instruction instead of its actual address
IP and CS are both 16-bit registers, but a 20-bit address is needed to access
memory
To change the active code segment, just load the new value in CS register
+ Example – Intel 8086 (Register Organizations) (8) 23
Data Registers
8088/8086 has four general purpose data registers:
A - Accumulator register
B - Base register
C - Count register
D - Data register
During program execution, they hold the frequently accessed values or results
All general purpose data registers can be used as the source or destination of
an operand during arithmetic operations (e.g. ADD) or logic operations (e.g.
AND).
The advantage of storing these data in internal registers instead of memory is
that they can be accessed much faster
+ Example – Intel 8086 (Register Organizations) (9) 24
Each of these registers can either be accessed as a whole (16 bits) or as two
8-bit registers
On the other hand, when referencing one of these registers on 8-bit basis,
the register name is followed by the letter H or L, identifies the high byte or
low byte.
H L
15 87 0
AX
Accumulator
AH AL
BX
Base
BH BL
CX
Count
CH CL
DX
Data
DH DL
+ Example – Intel 8086 (Register Organizations) 25
(10)
Pointer and Index Register
There are four other general-purpose registers:
i. Two pointer registers
- Base Pointer (BP) and Stack Pointer (SP)
ii. Two index registers
- Source Index (SI) and Destination Index (DI)
These registers store offset address, which represents the displacement of a storage
location in memory from the segment base address (value in segment registers)
They are used as pointer or index to select a specific location within a 64Kbyte
segment
Index registers are used to refer to data in memory relative to data segment or
extra segment
+ Example – Intel 8086 (Register 26
Organizations) (11)
Pointer registers are used to access memory locations relative to the stack
segment
The value held inside these registers can be read, loaded or modified
through software
Unlike data registers, the pointer and index registers can only be accessed
on 16-bit basis
+ Example – Intel 8086 (Register Organizations) 27
(12)
Status Register
The status register (also called flags register), is a 16-bit
register within 8088/8086
Only 9 bits of this register are used
X X X X OF DF IF TF SF ZF X AF X PF X CF
(13)
6 status flags: carry flag (CF), parity flag (PF), auxiliary
carry flag (AF), zero flag (ZF), sign flag (SF) and overflow flag (OF)
The logic state of these flags indicate conditions that are produced as the result of
executing an instruction
Carry flag (CF): CF is set (1) if there is a carry out or borrow in for the most
significant bit of the result when executing an instruction; otherwise, CF is cleared
(0)
Parity flag (PF): PF is set (1) if the result produced by an instruction has even
parity (even number of 1); otherwise, PF is cleared (0)
Auxiliary carry flag (AF): AF is set (1) if there is a carry-out from the low nibble
into the high nibble or a borrow-in from the high nibble into the low nibble of the
lower byte in a 16-bit word; otherwise, AF is cleared (0)
Zero flag (ZF): ZF is set (1) if the result of an instruction is zero; otherwise, ZF is
cleared (0)
+ Example – Intel 8086 (Register Organizations) 29
(14)
Sign flag (SF): The MSB of the result is copied into SF. Thus, SF is set (1) is the
result is a negative number or cleared (0) if it is positive.
Overflow flag (OF): When OF is set, it indicates that the signed result is out of
range. If the result is not out of range, OF remains reset
E.g. Consider executing the following instructions:
MOV AL, 75
CF = 0 There is no carry out from MSB
ADD AL, 85
PF = 1 The result has even number of 1
1 1 1 1 1 1 AC = 1 There is a carry from bit 3 to bit 4
0 1 0 0 1 0 1 1 7510 ZF = 0 Result is not zero
+ 0 1 0 1 0 1 0 1 8510 SF = 1 Sign bit is 1
1 0 1 0 0 0 0 0 16010 OF = 1 Out of the range (-12810 to 12710)
+ Example – Intel 8086 (Register Organizations) 30
(15)
Another 3 bits are known as Control Flags: direction flag (DF), interrupt
enable flag (IF) and trap flag
Trap flag (TF): If TF is set (1), the 8088/8086 goes into single-step mode
of operation (for program debugging)
Direction flag (DF): This flag determines the direction of string operations;
if DF is set (1), string data is transferred from high address to low address;
otherwise, the string data is transferred from low address to high address
+ Summary Structure and Function
31
of CPU, Instruction
Cycle
Lecture B - 02
Processor organization
Register organization
User-visible registers
Control and status registers
Instruction cycle
The indirect cycle
Data flow