Академический Документы
Профессиональный Документы
Культура Документы
It is a 16 bit p.
8086 has a 20-bit address bus can access
up to 220 memory locations(1 MB)
It can support up to 64K I/O ports.
It provides 14, 16-bit registers.
It has multiplexed address and data bus
AD0- AD15 and A16 A19.
It requires +5V power supply.
A 40 pin dual in line package.
It can pre fetches up to 6 instruction bytes
from memory and queues them in order to
speed up instruction execution.
8086 is designed to operate in two modes,
Minimum and Maximum.
Arithmetic Logic Unit (ALU)
Addition OPERAND A
Subtraction
Multiplication
RESULT
Division
Comparison
Logic Operations
OPERAND B
CONTROL
Arithmetic Logic Unit (ALU)
A B F Y
n bits n bits
0 0 0 A+ B
0 0 1 A -B
Carry
0 1 0 A -1
Y= 0 ? F 0 1 1 A and B
1 0 0 A or B
A>B?
1 0 1 not A
Y
Signal F control which function will be conducted by ALU.
Signal F is generated according to the current instruction.
BIU contains:
Instruction queue
Segment registers
Instruction pointer
Address adder.
The instruction bytes are transferred to the
instruction queue.
BIU provides a full 16-bit bidirectional data
bus and 20-bit address bus.
The BIU is responsible for performing all
external bus operations.
The BIU uses a mechanism known as an
instruction stream queue to implement a
pipeline architecture.
Pipelined architecture of the 8086 microprocessors
Pipelining Fetch Stage
Get Instruction From Memory
Store In Instruction Register
Instruction #1
Pipelining Decode Stage
Determine Instruction Type
Get Necessary Data
Setup ALU
Instruction #2 Instruction #1
Pipelining Execute Stage
Perform Required Operation
Store Result In Result Register
DS Data Segment
SS Stack Segment
ES Extra Segment
Read-Only Memory (ROM)
Instruction Manual
Examples
CS 3 4 8 A 0 SS 5 0 0 0 0
IP + 4 2 1 4 SP + F F E 0
Instruction address 3 8 A B 4 Stack address 5 F F E 0
DS 1 2 3 4 0
DI + 0 0 2 2
Data address 1 2 3 6 2
Fetching Instructions
Where to fetch the next instruction?
8088 Memory
CS 1234
IP 0012 12352 MOV AL, 0
12352
Update IP
After an instruction is fetched, Register IP is updated as follows:
For Example: the length of MOV AL, 0 is 2 bytes. After fetching this instruction,
the IP is updated to 0014
Accessing Data Memory
There is a number of methods to generate the memory address when
accessing data memory. These methods are referred to as
Addressing Modes
Examples:
Direct addressing: MOV AL, [0300H]
DS 1 2 3 4 0 (assume DS=1234H)
0 3 0 0
Memory address 1 2 6 4 0
DS 1 2 3 4 0 (assume DS=1234H)
0 3 1 0 (assume SI=0310H)
Memory address 1 2 6 5 0
EXECUTION UNIT
The Execution unit is responsible for
decoding and executing all instructions.
EU contains:
Control circuitry
Instruction decoder
ALU
Pointer and Index registers
Flag register.
EU Operation
INTA
Data bus
M/IO, HLDA
Device 2
DT/R,
RD,
Bus
WR,
DEN and Memory
INTR are all in the high Z state.
When the HOLD line goes high, it
indicates to the processor that another
master is requesting the bus access.
HLDA
The 8086 signals external device that it is in this
state by switching its HLDA output to logic 1 level.
The processor, after receiving the HOLD request,
issues the hold acknowledge signal on HLDA pin, in
the middle of the next clock cycle after completing
the current bus cycle.
At the same time, the processor floats the local bus
and control lines.
When the processor detects the HOLD line low, it
lowers the HLDA signal. HOLD is an asynchronous
input, and is should be externally synchronized.
If the DMA request is made while the
CPU is performing a memory or I/O
cycle, it will release the local bus during
T4 provided:
The request occurs on or before T2 state of
the current cycle.
The current cycle is not operating over the
lower byte of a word.
The current cycle is not the first
acknowledge of an interrupt acknowledge
sequence.
A Lock instruction is not being executed.
Minimum mode 8086 system
In a minimum mode 8086 system, the
microprocessor 8086 is operated in minimum
mode by strapping its MN/MX pin to logic 1.
In this mode, all the control signals are given out
by the microprocessor chip itself. There is a single
microprocessor in the minimum mode system.
The remaining components in the system are
latches,
transreceivers
clock generator
memory and I/O devices.
Some type of chip selection logic may be required
for selecting memory or I/O devices, depending
upon the address map of the system.
BUS Buffering and Latching
Latches
are generally buffered output D-type
flip-flops like 74LS373 or 8282.
They are used for separating the valid
address from the multiplexed
address/data signals and are controlled
by the ALE signal generated by 8086.
Transceivers
are the bi-directional buffers and some times they are
called as data amplifiers.
They are required to separate the valid data from the time
multiplexed address/data signals.
They are controlled by two signals namely,
DEN and
DT/R.
The DEN signal indicates the direction of data, i.e. from or
to the processor. The system contains memory for the
monitor and users program storage.
Usually, EPROM are used for monitor storage, while RAM
for users program storage.
The clock generator generates the clock from
the crystal oscillator and then shapes it and
divides to make it more precise so that it can
be used as an accurate timing reference for
the system.
The clock generator also synchronizes some
external signal with the system clock. The
general system organization is as shown in
below fig.
It has 20 address lines and 16 data lines, the
8086 CPU requires three octal address
latches and two octal data buffers for the
complete address and data separation.
The working of the minimum mode configuration
system can be better described in terms of the
timing diagrams rather than qualitatively
describing the operations.
The opcode fetch and read cycles are similar.
Hence the timing diagram can be categorized in
two parts, the first is the timing diagram for read
cycle and the second is the timing diagram for
write cycle.
The read cycle begins in T1 with the assertion of
ALE signal and also
M / IO signal.
During the negative going edge of this signal, the
valid address is latched on the local bus.
The BHE and A0 signals address low, high or
both bytes.
From T1 to T4:
the M/IO signal indicates a memory or I/O operation.
At T2:
the address is removed from the local bus and is
sent to the output.
The bus is then tristated.
RD control signal is also activated in T2.
The read (RD) signal causes the address
device to enable its data bus drivers.
After RD goes low, the valid data is available on
the data bus.
The addressed device will drive the READY
line high. When the processor returns the
read signal to high level, the addressed
device will again tristate its bus drivers.
A write cycle also begins with the assertion of
ALE and
the emission of the address.
The M/IO signal is again asserted to indicate a
memory or I/O operation.
In T2:
after sending the address in T1, the processor
sends the data to be written to the addressed
location.
The data remains on the bus until middle of
T4 state.
The WR becomes active at the beginning of
T2 (unlike RD is somewhat delayed in T2 to
provide time for floating).
The BHE and A0 signals are used to select
the proper byte or bytes of memory or I/O
word to be read or write.
The M/IO, RD and WR signals indicate the
type of data transfer as specified in table
below.
Data Transfer table
M / IO RD WR Transfer Type
0 0 1 I / O read
0 1 0 I/O write
1 0 1 Memory read
1 1 0 Memory write
Hold Response sequence:
The HOLD pin is checked at leading edge of each
clock pulse.
If it is received active by the processor before T4
of the previous cycle or during T1 state of the
current cycle, the CPU activates HLDA in the next
clock cycle and for succeeding bus cycles, the bus
will be given to another requesting master.
The control of the bus is not regained by the
processor until the requesting master does not
drop the HOLD pin low
When the request is dropped by the requesting
master, the HLDA is dropped by the processor at
the trailing edge of the next clock.
Maximum Mode Interface
When the 8086 is set for the maximum-mode
configuration, it provides signals for
implementing a multiprocessor / coprocessor
system environment.
By multiprocessor environment we mean that
one microprocessor exists in the system and
that each processor is executing its own
program.
Coprocessor also means that there is a second
processor in the system. In this two processor
does not access the bus at the same time.
One passes the control of the system bus to the
other and then may suspend its operation.
In this mode the available pins:
RQ/GT0
RQ/GT1
LOCK
S2
S1
S0
QS0
QS1
This mode uses :
Bus controller(8288)
Bus arbiter(8289)
Queue status signals
Local bus control signals
8288 Bus Controller
Separate signals are used for I/O ( IORC and IOWC ) and memory ( MRDC and MWTC ).
Also provided are advanced memory ( AIOWC ) and I/O ( AIOWC ) write strobes plus INTA .
Bus Controller(8288)
It provides
Bus Command and
Control Signals
8086 does not directly provide all the signals that
are required to control
the memory
I/O and
Interrupt interfaces.
Specially the
WR,
M/IO,
DT/R,
DEN,
ALE and
INTA, signals are no longer produced by the 8086.
Instead it outputs three status signals:
S0, S1, S2 prior to the initiation of each bus
cycle.
This 3- bit bus status code
identifies which type of bus cycle is to follow.
S2S1S0 are input to the external bus
controller device
The bus controller generates
the appropriately timed command and
control signals.
Bus Status Codes
Status Inputs CPU Cycles 8288
S2 S1 S0 Command
Some functions are not available It allows the use of 8087 coprocessor;
in minimum mode it also provides other functions
CLK
ALE
float float
AD0..AD15 Address Valid Data
DT/R
DEN
/MRDC or /IORC
Read Cycle
Timing Diagram : 8086 Write Cycle
T1 T2 T3 T4
CLK
ALE
DT/R
DEN
/MWTC or /IOWC
Write Cycle
8086 Read Cycle (1 Wait State)
T1 T2 T3 Tw T4
CLK
ALE
8284 RDY
READY
float float
AD0..AD15 Address Valid Data
DT/R
DEN
/MRDC or /IORC
Register organization
The 8086 has four groups of the user
accessible internal registers.
The 8086 has a total of fourteen 16-bit
registers
Classification of registers:
General purpose registers
Special purpose registers
Flag register
Pointer and index registers
General purpose Registers:
All general purpose registers of the 8086
microprocessor can be used for arithmetic
and logic operations.
The general purpose registers are:
Accumulator
Base register
Counter register
Data register
General Purpose Registers
15 8 7 0
AX AH AL Accumulator
BX BH BL Base
Data Group
CX CH CL Counter
DX DH DL Data
SP Stack Pointer
BP Base Pointer
Pointer and
Index Group
SI Source Index
DI Destination Index
Accumulator
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
- NT IOPL OF DF IF TF SF ZF - AF - PF - CF
Parity:
Means counting of number of 1s in the unit of
data
Could be even number or odd number
Auxiliary carry flag:
Enables/disables interrupts
Dictates whether or not system interrupt
can occur if logic 1:enabled
0:disabled
Or, Setting this bit enables maskable
interrupts.
Direction flag:
Nested Task:
Indicates if current task is nested
Addressing modes
Immediate
Direct
Register
Register indirect
Indexed
Register relative
Based index
Relative based index
Immediate Addressing
MOV AX,0005H
Copies 0005H into AX
the data is provided in the instruction.
Direct addressing:
the instruction operand specifies the
memory address where data is located.
MOV AX,[5000H]
Copies the contents of data segment
memory location 5000H into AX
Physical address: 10*DS+5000H
Register addressing
Destination Source
Memory Accumulator
Accumulato Memory
r
Register Register NO MOV
Register Memory
Memory Register Mem
Mem
Register Immediate Imm Seg Reg
Memory Immediate Seg Reg Seg reg
Seg reg Reg 16
Seg reg Mem 16
Reg 16 Seg reg EX: MOV AL, BL
Memory Seg reg
Data Transfer Instructions - XCHG
Destination Source
Accumulator Reg 16
Example: XCHG [1234h], BX
Memory Register
Register Register
NO XCHG
MEMs
Register Memory
SEG REGs
The Stack
The stack is used for temporary storage of information such as data or
addresses; for instance when a CALL is executed the 8088
automatically PUSHes the current value of CS and IP onto the stack.
Other registers can also be pushed
Before return from the subroutine, POP instructions can be used to pop
values back from the stack into the corresponding registers
Example for PUSH
Example for POP
Data Transfer Instructions LEA, LDS,
LES
Mnemonic Meaning Format Operation Flags
affected
LEA Load LEA Reg16,EA EA (Reg16) None
Effective
Address
LDS Load LDS Reg16,MEM32 (MEM32) None
Register (Reg16)
And DS
(Mem32+2) (DS)
7A 11000
BX 127A 12 11001
00
DI 1000 11002
30
11003
DS 3000
Ex.2 INC BX
INC WORD PTR [BX]
(BX)=0000000000111010
2s comp = 1111111111000110 = FFC6H
(CF)=1
Example
OR
Used in setting certain bits
xxxx xxxx OR 0000 1111 = xxxx 1111
(Set the upper four bits)
XOR
Used in inverting bits
xxxx xxxx XOR 0000 1111 = xxxxxxxx
-Example: Clear bits 0 and 1, set bits 6 and 7, invert bit
5 of register CL:
AND CL, OFCH ; 1111 1100B
OR CL, 0C0H ; 1100 0000B
XOR CL, 020H ; 0010 0000B
Shift Instructions
Shift Instructions
Destination Count
Register 1
Register CL
Memory 1
Memory CL
Ex.
; Multiply AX by 10
SHL AX, 1
MOV BX, AX
MOV CL,2
SHL AX,CL
ADD AX, BX
Ex. What are the results of SAR CL, 1
if CL initially contains B6H? DBH
Ex. What are the results of SHL AL, CL
if AL contains 75H and CL contains 3? A8H
Rotate Instructions
Rotate Instructions
Destination Count
Register 1
Register CL
Memory 1
Memory CL
Ex. What is the result of ROL BTRE PTR [SI], 1
if SI is pointing to a memory location that contains 41H? (82H)
Example
Write a program that counts the number of 1s in a
byte and writes it into BL
DATA1 DB 97 ; 61h
SUB BL, BL ; clear BL to keep the number of 1s
MOV DL, 8 ; Counter
MOV AL, DATA1
AGAIN: ROL AL,1 ; rotate left once
JNC NEXT ; check for 1
INC BL ; if CF=1 then add one to count
NEXT: DEC DL ; go through this 8 times
JNZ AGAIN ; if not finished go back
NOP
8086 Instruction Sets 7 Types
4. Control Transfer
Conditional Transfers Conditional Transfers(continue)
JA/JNBE JNS
JAE/JNB JO
JB/JNAE
JP/JPE
JBE/JNA
JS
JC
JE/JZ Unconditional Transfers
JG/JNLE CALL
JGE/JNL RET
JL/JNGE JMP
JLE/JNG Iteration Controls
JNC LOOP
JNE/JNZ LOOPE/LOOPZ
JNO LOOPNE/LOOPNZ
JNP/JPO JCXZ
5. String instructions
8086 instruction set
CMPS Compare byte or word string
LODS Load byte or word string
MOVS Move byte or word string
MOVSB(MOVSW) Move byte string (word string)
REP Repeat
REPE (REPZ) Repeat while equal (zero)
REPNE (REPNZ) Repeat while not equal (not zero)
SCAS Scan byte or word string
STOS Store byte or word string
8086 Instruction Sets 7 Types
6.Interrupt Instructions
INT
INTO
IRET
8086 Instruction Sets 7 Types
7. Process Control
Flag Operations External Synchronization
STC HLT
LCL WAIT
CMC ESC
STD LOCK
CLD No Operations
STI NOP
CLI
ASSEMBLER DIRECTIVES
or
Pseudo-Operations
Depending upon the operation performed
by these assembler directives they are
classified into:
Data definition & storage allocation
directives
-DB (define byte)
-DW (define word)
-DD (define double word)
-DQ (define quadrant)
-DT (define ten bytes)
-STRUC (define structure)
Program Organization Directives:
-SEGMENT (logical segment)
-ENDS (end of segment)
-ASSUME (assume logical segment name)
Alignment Directives:
-EVEN (align on even memory address)
-ORG (origin)
3
DB, DW, DD, DQ, DT
Memory Pseudo-Operation( Memory Directive)
<varname> DB <exp>[,<exp>,]
<varname> DW <exp>[,<exp>,]
<varname> DD <exp>[,<exp>,]
<varname> DQ <exp>[,<exp>,]
<varname> DT <exp>[,<exp>,]
DB : Define Byte ( allocate ONE BYTE, 8 bits)
DW: Define Word ( allocate ONE WORLD, 16bits)
DD : Define DoubleWord (allocate two words, 32bits)
DQ : Define Quadword ( allocate four words, 64 bits)
DT : Define TenBytes ( allocate ten Bytes, 80 bits)
EXAMPLE SOURCE PROGRAM
3 continue
The directives (Dn) allocate memory in units
specified by the second letter of the directive
(each directive may allocate one or more of its
units at a time)
To define variables
To initial partions of memory
: NUM_BASE DB 16
FILLER DB ?
TABLE DB 10 DUP(A)
BUFFER DB 10 DUP(?)
EXAMPLE SOURCE PROGRAM
4
PROC
Memory Pseudo-Operation (Memory Directive)
<procname> PROC [NEAR] or [FAR]
..
RET
<procname> ENDP
Default is no operand NEAR
Use FAR if:
1. The procedure name is an operating system entry point
2. The procedure will be called from code with has another
ASSUME CS value.
*each proc block should contain a RET.
EXAMPLE SOURCE PROGRAM
5
ASSUME
Memory Pseudo operation (Memory
Directive)
ASSUME <seg-reg>:<seg-name>[,.]
ASSUME tells the assembler that the
sysbols in the segment or group can be
accessed using this segment Register.
EXAMPLE SOURCE PROGRAM
6
END
Memory Pseudo-Operation ( Memory
Directive)
END [<exp>]
*The END statement specifies the end of
the program