8086
8086
8086
By Shilpa Chaman 2
By Shilpa Chaman 3
By Shilpa Chaman 4
By Shilpa Chaman 5
By Shilpa Chaman 6
By Shilpa Chaman 7
By Shilpa Chaman 8
By Shilpa Chaman 9
By Shilpa Chaman 10
Fetching the next instruction while current
instruction is under execution is called
pipelining.
What happens to queue when jump or call
instruction is executed ?
By Shilpa Chaman 11
By Shilpa Chaman 12
By Shilpa Chaman 13
By Shilpa Chaman 14
By Shilpa Chaman 15
Allow the memory capacity to be 1Mb even
though the addresses associated with the
individual instructions are only 16 bits wide.
Facilitate the use of separate memory areas for
the program, its data and the stack.
Permit a program and/or its data to be put into
different areas of memory each time the
program is executed.
Multitasking becomes easy.
By Shilpa Chaman 16
By Shilpa Chaman 17
By Shilpa Chaman 18
Control Flag:- Out of nine active flags, six are conditional
flags and the remaining three are called as the control
flag.The three control flags are:
1. The Trap flag(TF)
2. The interrupt flag(IF)
3. The direction flag(DF)
By Shilpa Chaman 19
By Shilpa Chaman 20
A] Data Category B] Branch Category
A] Data Category
1) Immediate Addressing
2) Direct Addressing
By Shilpa Chaman 21
5) Register Relative addressing
6) Base Index addressing
7) Relative Base Index addressing
8) Implied /Implicit Addressing
B] Branch Category :
1) Intrasegment Direct
2) Intersegment Indirect
3) Intrasegment Direct
4) Intersegment Indirect
By Shilpa Chaman 22
In this mode, 8 or 16 bit data can be specified as part of the
instruction.
OP Code
Immediate Operand
Example 1:
MOV CL, 03 H
Moves the 8 bit data 03 H into CL
Example 2:
MOV DX, 0525 H
Moves the 16 bit data 0525 H into DX
In the above two examples, the source operand is in immediate
mode and the destination operand is in register mode
By Shilpa Chaman 23
The operand to be accessed is specified as residing in an internal
register of 8086. However only the data registers can be accessed
as either a byte or word
Example 1:
MOV DX (Destination Register) , CX (Source Register)
Which moves 16 bit content of CS into DX.
Example 2:
MOV CL, DL
Moves 8 bit contents of DL into CL
By Shilpa Chaman 24
The instruction Opcode is followed by an affective address, this
effective address is directly used as the 16 bit offset of the
storage location of the operand from the location specified by the
current value in the selected segment register.he default segment
is always DS. The 20 bit physical address of the operand in
memory is normally obtained as
PA = DS : EA
Example 1 :
MOV CX, [0040]
If the 16 bit value assigned to the offset is 0040 and [DS] = 3050.
Then BIU generates the 20 bit physical address 30540 H.The
content of 30540 is moved to CL.The content of 30541 is moved to
CH
Example 2 :
MOV CH, [0040]
If [DS] = 3050 and 0040 is offset then 8 bit content of memory
location 30540 is moved to CH.
By Shilpa Chaman 25
Instruction
Opcode Address A
Memory
Operand
The EA is specified in either pointer (BX) register or
an index (SI or DI) register. The 20 bit physical
address is computed using DS and ES.
By Shilpa Chaman 27
Instruction
Registers
EA : [BX]
PA : [DS] + [EA]
The 8 bit content of this memory location
is moved to AL.
By Shilpa Chaman 29
Instruction
Registers
By Shilpa Chaman 31
Instruction
Registers
BH.
By Shilpa Chaman 33
Instruction
Registers
BH.
By Shilpa Chaman 35
Instruction
Registers
3000
Physical address (PA) = 31208
8 bit content of CL is moved to 31208
memory address.
By Shilpa Chaman 37
In this mode operands are implied and hence are not specified in
the instruction.
This instruction is very compact
Example 1:
STC : Set Carry Flag
Example 2:
CLD : Clear Direction Flag
By Shilpa Chaman 38
By Shilpa Chaman 39
By Shilpa Chaman 40
By Shilpa Chaman 41
By Shilpa Chaman 42
Low / Even
High / Odd
Bank
Bank
Vcc
GND
CLK
Address/Data bus: 20 bits vs 8 bits
multiplexed
Status signals: A16-A19 multiplexed with
status signals S3-S6 respectively
S3 and S4 together form a 2 bit binary
code that identifies which of the internal
segment registers was used to generate the
physical address that was output on the
address bus during the current bus cycle.
S5 is the logic level of the internal
interrupt enable flag, s6 is always logic 0.
BUS CYCLE AND TIME STATES
T-State
An operation takes an integer number of T-States
T1 T2 T3 T4
Wait and Idle States
Idle State
No bus activity required
Each is 1 clock period long
Occurs when instruction queue is full or
the MPU does not need to read/write to
memory
Wait State
Triggered by events external to MPU
Buffer full will trigger a wait state
Triggered by READY pin
Inserted between T3 and T4
TIMING DIAGRAM OF 8086
Timer States
T1
Address placed on bus
ALE active
T2
Change direction of Data bus for READ instructions
T3-4
Data transfer occurs
T1 - start of bus cycle. Actions include setting control signals to give the
required values for ALE, DTR, IO/M putting a valid address onto the
address bus.
CLK
M/IO
ALE
MEMORY ACCESS TIME
ADDR/ RESERVED VALID
A15-A0
DATA FOR DATA D15-D0
ADDR/ A19-A16
STATUS
RD/INTA
READY
DT/R
DEN
T1 T2 T3 TW T4
CLK
M/IO
ALE
ADDR/
A15-A0 DATA OUT (D15-D0)
DATA
ADDR/ A19-A16
STATUS
WR
READY
DT/R
DEN
Write Cycle Timing Diagram for Minimum Mode
T1 T2 T3 TW T4 T1
ALE
BHE S7 S3
ADD / STATUS A19 A16
WR
DEN
DT / R
What is the duration of the bus cycle in the 8088
based microcomputer if the clock is 8MHz and two
wait states are inserted
http://en.wikipedia.org/wiki/Crystal_oscillator
BASIC 8086 MINIMUM MODE SYSTEM
MN/MX
CLK
8284A M/IO
CLOCK READY
INTA
GENERATO RESET
RD
R
WR 8282
DT/R LATCH
DEN
ALE ADDR
WAIT STATE
GENERATOR AD0-
AD15
A16-A19
8286
TRAN-
ADDR/DATA CEIVER
DATA
ALE
MRDC
DT / R
DEN
Memory Write Timing in
Maximum mode.
Clk
ALE
ADD/STATUS BHE S7 S3
DT / R high
DEN
Classified into 7 categories:
1] Data Transfer
2] Arithmetic
3] Logical
4] Control
5]Processor Control Instructions
6] String Manipulation
7] Interrupt Control
By Shilpa Chaman 92
Note : Data Transfer Instructions do not affect any flags
1] MOV dest, src
Note that source and destination cannot be memory
location. Also source and destination must be same
type.
2] PUSH Src: Copies word on stack.
3] POP dest: Copies word from stack into dest.
Reg.
4] IN acc, port : Copies 8 or 16 bit data from port
to accumulator.
a) Fixed Port
b) Variable Port
5] OUT port, acc
By Shilpa Chaman 93
6] LES Reg, Mem: Load register and extra
segment
register with words from memory.
7] LDS Reg,Mem: Load register and data
segment
register with words from memory.
8] LEA Reg,Src: load Effective address.
(Offset is loaded in specified register)
9] LAHF: Copy lower byte of flag register into AH
register.
10] SAHF: Copy AH register to lower byte of flag
By Shilpa Chaman 94
11] XCHG dest, src: Exchange contents of
source and destination.
12] XLAT: Translate a byte in AL.
By Shilpa Chaman 95
1]ADD dest,src
2] ADC dest,src: Add with carry
3] AAA : ASCII adjust after addition.
By Shilpa Chaman 96
5] SUB dest, src
9] MUL src
By Shilpa Chaman 97
11] AAM: BCD adjust after multiply.
(works with AL only)
12]DIV src
Division.
15] DEC dest
By Shilpa Chaman 98
16] INC dest
17] CWD: Convert signed word to
signed word.
(CBW and CWD works only with AL, AX and
DX)
19] NEG dest: Forms 2s complement.
By Shilpa Chaman 99
1] AND dest, src
2] NOT dest: Invert each bit in destination
3] OR dest, src
4] XOR dest, src
5] RCL dest, count : Rotate left through Carry
Rotate as many times as directly specified in the
instruction. For more no.of rotations, count can be
specified in CL register.
By Shilpa Chaman 10
0
9] SAL/ SHL dest, count : Shift left and
append 0s on right.
10] SAR dest, count : Shift right retain a
0s on left
12] TEST dest, src: AND logically,
By Shilpa Chaman 10
1
13] CMP dest, src
CF, ZF and SF are used
By Shilpa Chaman 10
2
1]CALL : Call a procedure
Two types of calls:
i) Near Call ( Intrasegment)
ii) Far Call ( Intersegment)
2] RET : Return execution from
procedure
3] JMP : Unconditional Jump to specified
By Shilpa Chaman 10
3
4] JA / JNBE: Jump if above / Jump if not
below
The terms above and below are used when
we refer to the magnitude of Unsigned
number .
Used normally after CMP.
5] JAE / JNB / JNC
6] JB / JC / JNAE
7] JBE / JNA
8] JE/ JZ
By Shilpa Chaman 10
4
9] JCXZ: Jump if CX is Zero.
10] JG / JNLE: Jump if Greater /Jump if
By Shilpa Chaman 10
5
15] JNO : Jump if no overflow
16] JNS : Jump if no sign
17] JS
18] JO
19] JNP / JPO
20] JP / JPE
By Shilpa Chaman 10
8
9] NOP : No Operation
10] ESC: Escape
Executed by Co-processors and actions are
performed according to 6 bit coding in the
instruction.
11] LOCK : Assert bus lock Signal
This is a prefix instruction.
12] WAIT :Wait for test or Interrupt
Signal.
Assert wait states.
By Shilpa Chaman 10
9
1] MOVS/ MOVSB/ MOVSW
Dest string name,src string name
This instn moves data byte or word from
location in DS to location in ES.
By Shilpa Chaman 11
0
3] CMPS / CMPSB / CMPSW
Compare string bytes or string words.
By Shilpa Chaman 11
1
1]INT type
By Shilpa Chaman 11
2
end label end of program, label is entry point
proc far|near begin a procedure; far, near keywords
specify if procedure in different code
segment (far), or same code segment (near)
endp end of procedure
page set a page format for the listing file
title title of the listing file
.code mark start of code segment
.data mark start of data segment
.stack set size of stack segment
db define byte
dw define word (2 bytes)
dd define double word (4 bytes)
dq define quadword (8 bytes)
dt define tenbytes
equ equate, assign numeric expression to a name
Examples:
db 100 dup (?) define 100 bytes, with no initial values for bytes
db Hello define 5 bytes, ASCII equivalent of Hello.
maxint equ 32767
count equ 10 * 20 ; calculate a value (200)
1] ASSUME
Used to tell assembler the name of logical
segment. Ex. ASSUME CS: Code here
2] END
3] DB
4] DW
5] DD Define Double Word
6] DQ Define Quad Word
7] DT Define Ten Bytes
By Shilpa Chaman 11
5
8] PROC Procedure
PROC DELAY NEAR
9] ENDP
10] ENDS
11] EQU
12] EVEN: Align on even memory address.
13] ORG
14] OFFSET
Ex: MOV BX, Offset of Data Here
15] PTR Pointer
By Shilpa Chaman 11
6
16] LABEL
Ex: AGAIN LABEL FAR
17] EXTRN
Tells the assembler that the names or labels
following this directive is in some other
assembly module.
18] PUBLIC
By Shilpa Chaman 11
7
19] INCLUDE
Include source code from file.
20] NAME
To give specific name to module.
21] GROUP
Grouping of logical segments.
22] SEGMENT
23] SHORT
Operator that tells assembler about short displacement.
24] TYPE
Type of variable whether byte or word.
By Shilpa Chaman 11
8
mov cx,2000
mov ds,cx
mov ax,[0500h]
mov cx,3000
mov ds,cx
mov bx,[0600h]
add ax,bx
mov cx,5000
mov ds,cx
mov [0700h],ax
hlt
By Shilpa Chaman 11
9
MOV AX,WORD1 LB
MOV BX,WORD1 UB
MOV CX,WORD2 LB
MOV DX,WORD2 UB
ADD AX,CX
ADC BX,DX
MOV [0300],AX
MOV [0302],BX
By Shilpa Chaman 12
0
Mov ax,7000h
Mov ds,ax
Mov si, 0200h
Mov di, 0300h
Mov cx,0009h
By Shilpa Chaman 12
1
.model small
.stack 10h
extra segment
Array_cpy db
extra ends
data segment
Array db 11h,22h,33h,44h,55h,66h,77h,88h,99h;
data ends
code segment
assume cs:code, es:extra,ds:data
start: mov ax,data
mov ds,ax
mov es,ax
mov si, offset Array
mov di, offset Array_cpy
mov cx,09h
cld
Rep movsb
int 21h
code ends
end start By Shilpa Chaman 12
2
;Title : To find the largest Number in an array
.model small
.stack 10h
data segment
array db 5h,7h,6h,4h,10h,09h,03h,01h,02h,0h
largest db
data ends
code segment
Assume cs:code,ds:data
start: mov ax,data
mov ds,ax
xor ax,ax
mov cx,oah
mov si, offset array
Initial : inc si
cmp al,[si]
jnc Conti
mov al,[si]
Conti : loop Initial
mov largest,al
int 21h
code ends
end start
By Shilpa Chaman 12
3
Traverse a collection of elements
Move from the front to the end
Bubble the largest value to the end using
pair-wise comparisons and swapping
1 2 3 4 5 6
77 42 35 12 101 5
Traverse a collection of elements
Move from the front to the end
Bubble the largest value to the end using
pair-wise comparisons and swapping
1 2 3 4 5 6
42 Swap4277
77 35 12 101 5
Traverse a collection of elements
Move from the front to the end
Bubble the largest value to the end using
pair-wise comparisons and swapping
1 2 3 4 5 6
42 7735 Swap 35
77 12 101 5
Traverse a collection of elements
Move from the front to the end
Bubble the largest value to the end using
pair-wise comparisons and swapping
1 2 3 4 5 6
42 35 12 Swap 12
77 77 101 5
Traverse a collection of elements
Move from the front to the end
Bubble the largest value to the end using
pair-wise comparisons and swapping
1 2 3 4 5 6
42 35 12 77 101 5
No need to swap
Traverse a collection of elements
Move from the front to the end
Bubble the largest value to the end using
pair-wise comparisons and swapping
1 2 3 4 5 6
1 2 3 4 5 6
35 12 42 5 77 101
1 2 3 4 5 6
N-1
12 35 5 42 77 101
1 2 3 4 5 6
12 5 35 42 77 101
1 2 3 4 5 6
5 12 35 42 77 101
;Title Bubble sort(ascending)
.model small
.stack 10h
data segment
array db 5h,7h,6h,4h,10h,09h,03h,01h,02h,0h
data ends
code segment
Assume cs:code,ds:data
start: mov ax,data Swap : xchg al,[si+1]
mov ds,ax xchg al,[si]
xor ax,ax jmp Conti
mov dx,09h
Return: mov cx,dx exit : int 21h
mov si,offset array code ends
Check: mov al,[si] end start
cmp al,[si+1]
Jnc Swap
Conti : inc si
loop Check
dec dx
jnz Return
jmp exit
By Shilpa Chaman 13
2
;Title Bubble sort(descending)
.model small
.stack 10h
data segment
array db 5h,7h,6h,4h,10h,09h,03h,01h,02h,0h
data ends
code segment
Assume cs:code,ds:data
start: mov ax,data Swap : xchg al,[si+1]
mov ds,ax xchg al,[si]
xor ax,ax jmp Conti
mov dx,09h
Return: mov cx,dx exit : int 21h
mov si,offset array code ends
Check: mov al,[si] end start
cmp al,[si+1]
Jc Swap
Conti : inc si
loop Check
dec dx
jnz Return
jmp exit
By Shilpa Chaman 13
3