Unit-I (Second Half)
Unit-I (Second Half)
Features of 8086
1) It is a 16 bit microprocessor
2) It has 20 address lines(A0-A19) and 16 data lines(D0-15)
3) Operated in Two modes – Minimum mode and maximum mode –(Math
Coprocessor)
EU (Execution Unit)
Execution unit gives instructions to BIU stating from where to fetch the data and
then decode and execute those instructions. Its function is to control operations
on data using the instruction decoder & ALU. EU has no direct connection with
system buses as shown in the above figure, it performs operations over data
through BIU.
Let us now discuss the functional parts of 8086 microprocessors.
ALU
It handles all arithmetic and logical operations, like +, −, ×, /, OR, AND, NOT
operations.
Flag Register
It is a 16-bit register that behaves like a flip-flop, i.e. it changes its status
according to the result stored in the accumulator. It has 9 flags and they are
divided into 2 groups − Conditional Flags and Control Flags.
Conditional Flags
Control Flags
Control flags controls the operations of the execution unit. Following is the list of
control flags −
Trap flag − It is used for single step control and allows the user to execute
one instruction at a time for debugging. If it is set, then the program can
be run in a single step mode.
Interrupt flag − It is an interrupt enable/disable flag, i.e. used to
allow/prohibit the interruption of a program. It is set to 1 for interrupt
enabled condition and set to 0 for interrupt disabled condition.
Direction flag − It is used in string operation. As the name suggests when it
is set then string bytes are accessed from the higher memory address to
the lower memory address and vice-a-versa.
There are 8 general purpose registers, i.e., AH, AL, BH, BL, CH, CL, DH, and DL.
These registers can be used individually to store 8-bit data and can be used in
pairs to store 16bit data. The valid register pairs are AH and AL, BH and BL, CH
and CL, and DH and DL. It is referred to the AX, BX, CX, and DX respectively.
AX register − It is also known as accumulator register. It is used to store
operands for arithmetic operations. AH,AL
BX register − It is used as a base register. It is used to store the starting
base address of the memory area within the data segment. BH, BL
CX register − It is referred to as counter. It is used in loop instruction to
store the loop counter.
DX register − This register is used to hold I/O port address for I/O
instruction.
It is a 16-bit register, which holds the address from the start of the segment to
the memory location, where a word was most recently stored on the stack.
Flag Register (PSW- Program Status Word)
D15 D1 D0
- - - - O D I T S Z - AC - P - C
CS = 1000 H ; IP = 2FFF H
Then PA= CSx10 + IP
1000x10 + 2FFF= 12FFF H
10000+2FFF= 12FFF H
Example
o MOV AX, CX
o ADD AL, BL
o ADD CX, DX
Example
Direct Addressing: In direct addressing mode, the operand offset is given in the
instruction as an 8-bit or 16-bit displacement element.
Example
The instruction adds the content of the offset address 0301 to AL. the operand is
placed at the given offset (0301) within the data segment DS.
Register Indirect Addressing: The operand's offset/ displacement is placed in any
one of the registers BX, BP, SI or DI as specified in the instruction.
Example
Example
Example
Based Indexed Addressing: The offset of operand is the sum of the content of a
base register BX or BP and an index register SI or DI.
Here, BX is used for a base register for data segment, and BP is used as a base
register for stack segment.
Example
o ADD AX, [BX + SI]; [BP+SI]
o MOV CX, [BP + DI] [BX+DI]
Effective Address (Offset) = [BX or BP] + [SI or DI] + 8-bit or 16-bit displacement
Example
Program 1
MOV AX, [3000] ( Invalid = ADD [3000], [4000] )
ADD AX, [4000]
MOV [5000], AX
Program 2
Dividend: 5000H; Divisor: 6000; Quotient: 6200; remainder: 6021
MOV AX, [5000]
DIV [6000]
MOV [6200], AL
MOV [6021], AH
XVIII) CALL 8bit/16bit/32 bit offset address; CALL 80, CALL 23EF
CALL 2000:588F
XIV) RET
XX) IRET - Return from ISR- Interrupt Service Routine
LOOP instructions
1) LOOP 8bit address; Count value in the counter register, CX=9
2) LOOPE / LOOPZ 8bit address ( CX!=0 and ZF=1)
3) LOOPNE / LOOPNZ (CX!=0 and ZF=0)
MOV CX, 9
Label1: MOV AL, BL
…..
LOOP label1
Processor control instructions
I) CLC – clear carry flag
II) CMC - complement CF
III) STC- Set CF
IV) CLD - Clear Direction flag
V) STD – Set DF
VI) CLI – Clear Interrupt flag
VII) STI – Set IF
VIII) HLT
IX) WAIT
X) LOCK
XI) NOP
XII) ESC
8087- numeric coprocessor.. instruction set, architecture
ESC: instructions of coprocessor/ slave processor’s instruction
String Manipulation Instructions
Default Source Segment and Index Register: COLLEGE
Data Segment (DS) and Source Index (SI) Register
Default Destination Segment and Index Register:
Extra Segment (ES) and Destination Index (DI) Register
Direction flag (DF), DF=0 -> Auto increment mode, DF=1 -> Auto decrement mode
1) MOVSB - Move String Bytes from DS:[SI] to ES:[DI]
2) MOVSW - Move the String Word from DS:[SI] to ES:[DI] 2300 -> 4000,
2301->4001; DF=0
DF=1 ; 2300 -> 4000, 22FF -> 3FFF
3) CMPSB – Compare the String Bytes;
4) CMPSW - Compare the String Words;
5) LODSB – Load the String bytes at DS:[SI] into AL
6) LODSW - Load the String Words at DS:[SI] into AX
7) STOSB – Store the String bytes in AL at ES:[DI]
8) STOSW - Store the String Words in AX at ES:[DI]
9) SCASB – Scan the string byte [ES:[DI] with AL]
10) SCASW - Scan the string word [ES:[DI] with AX]
11) REP – Repeat (Repeat the string instructions until CX becomes 0) CX=5
REP MOVSB;
12) REPE or REPZ – Repeat on Equal/ Repeat on zero flag is 1
(Repeat the string instructions if CX is not equal to 0 and ZF=1)
13) REPNE or REPNZ – Repeat on Not Equal/Repeat on Not Zero flag
(Repeat the string instructions if CX is not equal to 0 and ZF!=0)
REPNE SCASB
String size is 8bytes, DS-5000, ES- 6000, SI-0100, DI-0200
MOV CX, 0008
MOV AX, 5000H
MOV DS, AX
MOV AX, 6000H
MOV ES, AX
MOV SI, 0100H
MOV DI, 0200H
CLD
REP MOVSB
HLT