Beruflich Dokumente
Kultur Dokumente
The Microprocessor
and The Computer
Input Output
port port
Memory unit:
RAM, ROM,
Input port Output port
and hard disk
Address bus
Control bus
Microprocessors
Arithmetic
Logic Register
Unit Array
(ALU)
Control
Unit
Microprocessor Buses
The three buses mentioned earlier are part of the internal and
external connections for microprocessors to allow data,
addresses, and control signals to be moved.
1) address bus,
2) data bus,
3) control and status signals,
4) power supply and frequency signals,
5) externally initiated signals, and
6) serial I/O ports.
8085 Architecture
Figure below shows the internal architecture of the 8085. It
includes the following:
ALU(Arithmetic/Logic Unit),
Timing and Control Unit,
Instruction Register and Decoder,
7
Register Array,
Interrupt Control, and
Serial I/O Control.
THE ALU
The arithmetic/logic unit performs the arithmetical and logical
functions on 8-bit internal data path. The arithmetic unit is
responsible for fundamental arithmetic operations such as
addition and subtraction, while the logical unit performs logical
operations such as NOT, AND, OR, XOR, Rotate and clear
operation. The ALU consist of the accumulator, the temporary
register, the arithmetic and logic circuits, and five flags. The
temporary register is used to hold data during an
arithmetic/logic operation. The result is stored in the
accumulator, and the flags (flip-flops) are set or reset according
to the result of the operation.
REGISTERS
The 8085 include six register, one accumulator, and one flag
register, In addition it has 16-bit register: The stack pointer and
the program counter. They are described briefly as follows.
Temporary data register: The ALU has two inputs, one input is
supplied by the accumulator and other from this temporary
register.
S Z AC P CY
Out of the five flags, the AC flag is used internally for BCD
arithmetic; the instruction set does not include any conditional
jump instructions based on the AC flag. Of the remaining four
flags, the Z and CY flags are those most commonly used.
4. 16-bit Registers:
The instruction register and the decoder are major part of the
ALU. When any instruction is fetched from memory, it is first
loaded in the instruction register. The decoder decodes the
instruction and establishes the sequence of events to follow. The
instruction register is not programmable and cannot be accessed
through any instruction.
1. The contents of the data bus (4F) are placed in the instruction
register and decoded.
Arithmetic instructions
Logical instructions
Branching instructions
Machine control instructions
Types Examples
Between registers Copy the contents of register C
into register E
Specific data byte to a register Load register C with the data byte
or a memory location 45H
Between a memory location and From the memory location 1500H
a register to register B.
Between an I/O device and the From an input keyboard to the
accumulator accumulator
17
Arithmetic Instruction
Logical Operations
BRANCHING OPERATIONS
Addressing modes
Direct
Indirect
Immediate
Indexed
Relative
Register Direct
Register Indirect
Autoincrement Mode
Autodecrement Mode
Stack
20
BIU C-BUS
Σ
6
5
Instruction
B-BUS 4 Stream
ES
CS
3 Byte
2 Queue
SS 1
DS
IP
CONTROL SYSTEM
EU
A-BUS
ES AL
BH BL
CH CL
DH DL ARITHMETIC
SP LOGIC UNIT
BP
SI
DI
OPERANDS
FLAGS
possible only when the EU does not require the system bus. The
process of fetching the next instruction in advance while the EU
is executing the current instruction, is known as pipelining.
Segment Registers
The Bus Interface Unit contains four 16-bit segment registers.
They are,
1. Code Segment (CS) register
2. Data Segment (DS) register
3. Stack Segment (SS) register
4. Extra Segment (ES) register
These registers are used to store the 16-bit starting address of
the four memory segments. The BIU generates a 20-bit address
using the segment and the offset components of an address. BIU
can address the memory locations starting from 00000H to
FFFFFH (0 to 1Mb).
Registers
The 8086 processor provides a few fast, on-chip (within the
processor) storage elements known as registers. The registers
are 16-bit wide. Registers are grouped on the basis of the
meaning assigned to them. The 8086 processor registers are
shown in Figure.
Fourteen, 16-bit hardware registers are divided into five groups
are listed below.
♦ General Purpose Registers AX, BX, CX, and
DX
♦ Pointer and Index Registers SP, BP, SI,
and DI
♦ Segment Registers CS, DS, ES, and
SS
♦ Instruction Pointer Register IP
♦ Flag Register FR (no specific
name)
AX, BX, CX, and DX are general-purpose 16-bit registers. Each
of these 16-bit registers can also be considered as two 8-bit
registers distinguished as high and low order bytes of the
respective 16-bit registers and referenced as AH, AL, BH, BL,
CH, CL, and DH, DL. The register SP points to the current top
of the stack, while BP register is used as a stack pointer. The SI
and DI are the source and destination index registers primarily
used for manipulating strings. The code segment (CS), the data
25
segment (DS), the extra segment (ES) and the stack segment
(SS) registers hold the starting addresses of their respective
segments. The instruction pointer-(IP) register points to the
location of the next instruction to be executed. It is used with the
CS register to fetch the next instruction from memory. The 8086
processor has nine, I-bit flags for recording the status of CPU
after the execution of each instruction.
Flag Register
The 16-bit flag register of the 8086 processor stores information
about the status of the processor and the status of the instruction
executed most recently. The format of the flag register is shown
in Figure (a). It consists of two parts, status flags and control
flags. The flag register is modified or read directly through
special instructions known as the processor control instructions
such as CLD, STI, CLC, STD, etc., and through arithmetic
instructions. The Flag Register contains the following flags.
• C -Carry flag • Z -Zero flag • I - Interrupt
flag
• P -Parity flag • S -Sign flag • D -
Direction flag
• A -Auxiliary flag • T -Trap flag • O -
Overflow flag
Carry Flag: The carry flag is designated as CF. The carry flag
is set (CF= 1) if an addition produces a carry or if a subtraction
needs a borrow. Certain instructions like the processor control
26
8085 Compatible
flags
OF – Overflow Flag TF – Trap Flag AF – Auxiliary
Flag
DF – Direction Flag SF – Sign Flag PF – Parity
Flag
IF – Interrupt Flag ZF – Zero Flag CF – Carry Flag
27
U – Undefined
(a) 8086 flag register format
15 0 Flag
Register
15 8 7 0
A AH Accumulat
SI Source
Index Registers
Index
DI Destinatio
n Index
S Stack
Pointer Registers
P Pointer
B Base
P Pointer
C
Code
S
D Data
S
28
Segment Registers
Extra
S
S
S Stack
IP Instruction
Pointer
Zero Flag: The zero flag is designated as ZF. Zero flag is set
(ZF= 1) if an addition or a subtraction produces a zero result.
Certain conditional jump instructions can transfer control to the
target location based on the status of the zero flag.
AX Register
The register AX functions as the Accumulator. The register AX
is always involved in multiplication and division as the default
operand. The usage of AX register is the most efficient in data
movement, arithmetic, and logical operations. The register AX
is divided into two parts. The lower 8-bit of the AX register is
AL register and the higher 8-bit of the AX register is AH
register. The splitting of the AX register into AH and AL
registers is convenient for performing the byte-data operations.
BX Register
The register BX functions as the Base Register. It is used as a
pointer to a memory location. It is suitable for accessing the
elements of an array from the memory. The code for reading a
word from memory location 40 in DS into register AX is as
follows:
..
mov bx, 40 ; BX = address of the memory
location
mov ax, [bx] ; Read memory pointed to by BX
register
CX Register
The register CX functions as the Count Register. Loop and
Repeat instructions of 80x86 use CX register to hold repeat
count value. For example, to repeat a block of code 100 times,
the outline of the program is as follows:
mov cx, 100 ; CX = loop count
Beginofloop:
.. ; body of theloop
loop Beginofloop ; CX +- CX -1, if CX ≠ 0 then
Beginofloop
The register CX can be treated as two 8-bit registers CH and
CL, as in the case of AX, BX, and DX registers.
DX Register
The register DX functions as the Data Register. The register DX
is the only register used as an I/O address pointer in the IN and
OUT instructions. The following code will read a character
from the port number 100 and stores in AL register,
..
mov dx, 100 ; DX = port address = 100
in al, dx ; read from port pointed to by
register DX
The register DX is also involved in 16-bit multiplication
and division operations as the default operand. The
register DX is most efficiently used in data movement,
33
SI Register
The Source Index register is designated as SI. This is
especially used as a pointer to a memory location as in
die case of BX and D1 registers. It is suitable for
accessing the data array (elements of an array) from the
memory. The code for reading a word from a memory
location 40 in DS into the AX register is as follows:
..
mov si, 40 ; S1 = address of memory
location
mov ax, [si] ; read memory pointed to
by DS : SI register
34
DI Register
The Destination Index register is designated as DI. It is
especially used as a pointer to a memory location as in
the case of BX and SI registers. It is suitable for
accessing the data array from the memory. The code for
reading a word from memory location 40 in DS into AX
register is as follows:
..
mov di, 40 ; DI = address of the
memory location
mov ax, [di] ; read memory pointed to
by DS : DI register
The register DI is loaded with the offset of the memory
location in DS. The register DI is useful in accessing
contiguous memory locations, such as a text string. In
repeat string instructions, DI is used as a pointer to a
destination string element.
35
BP Register
The Base Pointer register is designated as BP. The use of
BP register as a pointer to a memory location is similar
to the use of BX, SI, and DI registers. The registers BX,
SI, and DI normally act as memory pointers relative to
the segment register DS (DI relative to ES in the case of
string instructions). The register BP points relative to the
stack segment register. The BP register is generally used
for accessing the parameters from the stack in the
procedures. The outline of the code for reading the first
parameter from the stack by the C language procedure
call convention is as follows:
..
push bp ; save BP onto the stack
mov bp, sp ; assign SP to BP
mov ax, [bp + 4] ; peek for stack and put the
contents
; into AX register
In short, BP is designed to provide support for passing of
parameters between the procedures, local variables, and
other stack based allocation and operations. The BP
register is mainly used to access any location directly in
the stack.
36
SP Register
The Stack Pointer register is designated as SP. This
register is dedicated for maintaining an area of memory
used as a stack. The stack is an area of memory into
which data can be stored and retrieved on the basis of
Last- In-First-Out (LIFO), i.e., the data stored last in a
stack is the first one to be retrieved. The stack is useful in
implementing procedure calls, recursions, passing of
parameters, creation of local variables, etc.
The register SP always points to the top of die stack
relative to SS. The process of storing data onto the stack
is known as push operation. It is performed by die PUSH
instruction; first, SP is decremented by 2 and then the
data is placed into a new location pointed to by SP. The
SP is decremented by 2, because, the stack in 80x86
system grows from higher to lower memory locations.
The process of retrieving (reading) the data from the
stack is known as pop operation. It is performed by the
POP instruction. First, the contents of the memory
location pointed to by SP is read and stored in the
destination and then SP is incremented by 2 so that SP
points to the next element in the stack after the pop
37
IP Register
The Instruction Pointer register is designated as IP. It
always holds the memory (offset) address of the next
instruction to be executed. As the instruction is executed,
X – Hexadecimal
digit
Physical Address = segment * 16 + Offset
20-Bit address
Figure: Computation of physical address
Segment Registers
Instruction Types
The 80×86 processor instructions are classified into four
groups depending on the number of operands explicitly
42
Addressing Modes
Addressing mode is defined as a method of specifying
the effective address of the operands in memory. The
addressing mode increases the flexibility of the
programming language and is useful in implementing the
constructs and data structures of the powerful high level
programming language.
Based Indexed
5. [BX + SI]
6. [BX + DI]
7. [BP + SI]
8. [BP + DI]
Register Relative
9. [BX + disp]
10. [BP + disp]
11. [SI + disp]
12. [DI + disp]
Relative Based Indexed
13. [BX + SI + disp]
14. [BX + DI + disp]
15. [BP + SI + disp]
16. [BP + DI + disp]
Note that, the 8086 processor does not allow the use of
the BP register independently in the addressing mode,
however, it can be used along with the index registers
and/or displacement.
The 24 types of addressing modes in the 8086
processor can be grouped into the following categories.
1. Immediate Addressing Mode
2. Implicit Addressing Mode
3. Direct Addressing Mode
4. Indirect Addressing Mode
5. Register Addressing Mode
6. Register Indirect
47
7. Based Indexed
8. Register Relative
9. Relative Based .Indexed
Phase of Execution
The phases of execution of the instruction are fetch,
decode, execute and write.
♦ The fetch phase performs fetching of the
instruction queue.
♦ The decode phase performs the decoding of the
instruction.
♦ The execute phase performs real (actual)
operations on the data.
♦ The write phase performs the operation of
storing and computed result at the destination.
Interrupt
Introduction
An interrupt refers to the change in state of the central
processing unit (CPU) as a result of a condition which is
external to the system or within the system. The terms
exception, trap, supervisor call, system call are the
synonyms of the term interrupt.
Intel defines interrupt as follows: -
48