0% found this document useful (0 votes)
8 views

Module 2.2 - Instruction Set - Addl Instrs

instruction set of 8086

Uploaded by

badri1401rockz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Module 2.2 - Instruction Set - Addl Instrs

instruction set of 8086

Uploaded by

badri1401rockz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

ECE3004

VIT BHOPAL UNIVERSITY

Module-II
Microprocessors & Microcontrollers

Dr. M Suresh
School of Electrical & Electronics Engineering
VIT BHOPAL UNIVERSITY

8086 Additional Instruction


XLAT:

XLAT can perform a byte translation using look-up table containing up to 256 elements

XLAT assumes that, the 256-byte table start at the address given by DS:BX and AL is used
as the index to point to the required element in the table prior to the execution of
VIT BHOPAL UNIVERSITY

XLAT.

The result of XLAT instruction is returned in the same register [AL]

• After execution of XLAT


• Assume prior to XLAT
Content of 12080H will
DS=1000H
be copied into AL
BX=2000H
register, So AL will be
AL=80H
22H [instead of 80H]
PA = DS:[BX+AL] = 12080H
• After XLAT onward, AL
will be considered as
22H [i.e. Index value is
changed]
BCD Numbers
Single digit BCD numbers are 0-9
It can be two digit BCD numbers 00-99
VIT BHOPAL UNIVERSITY

For example: 36 is called as “packed BCD number” and 3


& 6 separately called as “unpacked BCD numbers”
Addition of two BCD numbers : 35+36 = 71
In microprocessor programming, we can specify only
BINARY/HEX data
If we add it using BINARY/HEX : 35H + 36H = 6BH
We need to convert HEX result into BCD by using
additional instruction DAA
DAA : Decimal Adjust after Addition

Syntax: DAA
Meaning: This instruction is used to convert the result [of AL] of the
VIT BHOPAL UNIVERSITY

addition of two packed BCD numbers to a valid BCD number


This instruction MUST be followed by addition operation & the result has to
be only in AL [i.e. in the addition instruction, destination operand
MUST be AL]
If lower nibble is greater than 9 or AF=1 [carry transfer from D3 to D4]
then add 6 to the lower nibble of binary/hex result
If higher nibble is greater than 9 or CF=1 [carry transfer from D7 to D8]
then add 6 to the higher nibble of binary/hex result
Above two steps are automatically done by 8086 once DAA is executed
DAA instruction affects CF, AF, ZF, PF
Example
Assume that, we need to add 35 &36
[decimal/BCD numbers] and expected result
will be 71
VIT BHOPAL UNIVERSITY

Usually using ASM program:


MOV AL, 35H [AL = 6BH] But, we need the result as 71!
Here lower nibble [B] is greater that 9 so, add 6
MOV BL, 36H
AL = 6BH + 06H = 71H – which is BCD result
ADD AL, BL
DAA
Example

MOV AL, 39H MOV AL, 72H MOV AL, 99H


VIT BHOPAL UNIVERSITY

MOV BL, 39H MOV BL, 91H MOV BL, 99H


ADD AL, BL ADD AL, BL
ADD AL, BL
DAA DAA
DAA Here, HEX result is Here, HEX result is 32H
Here, HEX result is 72H 03H and CF=1. and AF=1, CF=1.
and AF=1. So, 6 is added in So, 6 is added in lower
higher nibble nibble and higher
So, 6 is added in lower nibble
BCD result = 63H and
nibble
CF=1 BCD result = 98H and
BCD result = 78H CF=1
AAA : ASCII Adjust after Addition
Numerical data coming into computer from a terminal is usually in ASCII code
In this code, number 0 to 9 are represented by ASCII code 30H to 39H
VIT BHOPAL UNIVERSITY

8086 allows to add the ASCII codes for two decimal digits without masking off the “3” in
the upper nibble of each. After the addition, AAA instruction is used to make sure
that the result is correct unpacked BCD
Syntax: AAA
Meaning: This instruction is used to convert the result [of AL] of the addition of two
ASCII numbers and represent the result in unpacked BCD numbers in AX
This instruction MUST be followed by addition operation & the result has to be only in
AL [i.e. in the addition instruction, destination operand MUST be AL]
If AF=1 [carry transfer from D3 to D4] then, AH is loaded with 01H and clears the
higher nibble of AL [lower nibble is converted to decimal]
If AF=0 [carry transfer from D3 to D4] then, AH is loaded with 00H and clears the
higher nibble of AL
Example: AAA

MOV AL, 35H MOV AL, 35H


VIT BHOPAL UNIVERSITY

MOV BL, 32H MOV BL, 39H


ADD AL, BL ADD AL, BL
AAA
AAA

AF =1, so, AH=01H


AX = 00 07H
AX = 01 04H
AAM: ASCII Adjust after Multiplication
For multiplication of ASCII numbers require that the
numbers first be converted into unpacked BCD format
VIT BHOPAL UNIVERSITY

Content of AL will be converted to unpacked BCD [like


AAA, AAS]
Follows multiplication instruction after multiplying two
one-digit unpacked BCD numbers
AAM converts from binary to unpacked BCD
If a binary result between 0000H to 0063H appears in AX
[operand in in AL], AAM converts it to BCD
AAM: Example

MOV AL, 05H


VIT BHOPAL UNIVERSITY

MOV BH, 09H


MUL BH [AX = 002DH]
AAM [AX = 0405H]
AAD : ASCII adjust before division
This instruction converts two unpacked BCD digits in AH and AL into the
equivalent binary number in AL
The adjustment must be made before dividing two unpacked BCD digits in
VIT BHOPAL UNIVERSITY

AX by an unpacked BCD byte


AAD must appear before DIV
Example:
MOV CL, 07H
MOV AX,0508H
AAD /AL=3AH : HEX equivalent of 58 decimal/
DIV CL
MOV [1200H], AX /1200H = 07H & 1201H = 09H/
HLT
4.4 Iteration Control Instructions

4.4.1 LOOP
VIT BHOPAL UNIVERSITY

4.4.2 LOOPE / LOOPZ


4.4.3 LOOPNE / LOOPNZ
4.4.4 JCXZ
LOOP – Jump to specified Label if CX! =0 After Auto decrement

**Used to repeat a series of instruction a number of


times.
**The number of time the sequence is repeated is
stored in CX register
Variants are LOOPE, LOOPZ, LOOPNE and LOOPNZ.
4.4 Iteration Control Instructions

4.4.1 LOOP Label


VIT BHOPAL UNIVERSITY

CX = CX-1; JUMP to the specified label if CX=! 0

LOOP BACK = DEC CX

JNZ BACK
4.4 Iteration Control Instructions

4.4.1 LOOP Label


VIT BHOPAL UNIVERSITY

CX = CX-1; JUMP to the specified label if CX=! 0

LOOP BACK = DEC CX

JNZ BACK

MOV CX,n
MOV AX,0000H
L1: ADD AX, CX
LOOP L1
VIT BHOPAL UNIVERSITY
4.4 Iteration Control Instructions

4.4.4 JCXZ Label


VIT BHOPAL UNIVERSITY

JUMP to the specified label if CX= 0

MOV CX,0000H MOV CX,0002H


JCXZ L1 JCXZ L1
---abc ---abc
L1: *** L1: ***

abc will be skipped abc will be executed


8086 INTERRUPTS
Sources of Interrupts in 8086:

Three types of interrupts sources are there in 8086:


VIT BHOPAL UNIVERSITY

1. An external signal applied to NMI or INTR input


pin (Hardware interrupt)
2. Execution of INTn (n=00H-FFH) instruction
(Software interrupt)
3. Interrupt caused by some error condition
produced in 8086 instruction
execution process.
VIT BHOPAL UNIVERSITY
VIT BHOPAL UNIVERSITY
VIT BHOPAL UNIVERSITY
8086 Interrupt Processing Steps
If an interrupt has been requested, the 8086 Microprocessor processes it by
performing the following series of steps:
VIT BHOPAL UNIVERSITY

1.Pushes the content of the flag register onto the stack to preserve the
status of IF and TF flags, by decrementing the stack pointer (SP) by 2

2.Disables the INTR interrupt by clearing IF in the flag register


3.Resets TF in the flag register, to disable the single step or trap interrupt
4.Pushes the content of the code segment (CS) register onto
the stack by decrementing SP by 2
5.Pushes the content of the instruction pointer (IP) onto the stack
by decrementing SP by 2
6.Performs an indirect far jump to the start of the interrupt service
routine (ISR) corresponding to the received interrupt.
cessor
Executes the Interrupt instruction

Jumps to the Interrupt Vector Table

Takes the CS and IP in the Vector Table


VIT BHOPAL UNIVERSITY

Pushes the existing CS and IP on the Stack

Loads the new CS and IP

Jumps to the ISR

Executes ISR

Comes back and continues the Main Program

Steps involved in processing an interrupt


instruction by the processor
Processing of an Interrupt by the 8086

Main Program Push flags register Interrupt Service


Clear IF and TF Routine (ISR)
VIT BHOPAL UNIVERSITY

Push CS and IP
Interrupt program
Interr Load CS and IP
:
upt :
Pop IP and CS :
Pop flags :
register :
IRET
:
VIT BHOPAL UNIVERSITY
4.5 Interrupt Instructions

4.5.1 INT type


VIT BHOPAL UNIVERSITY

Type is a 8 bit HEX number ranging from 00H to FFH [256


numbers]
EX: INT 00H; INT 32H; INT FFH
These instructions are type of “intersegment transfer”, that
means both CS and IP will be modified
Each type [00H to FFH] tells 8086 to modify CS and IP from
specific memory location
These location are computed as shown in next slide
4.5 Interrupt Instructions

Ex: INT 00H


VIT BHOPAL UNIVERSITY

CS = 0000H
IP = type*4 = 0000H
PA is = CS x 10H + IP = 0000H x 10H + 0000H = 00000H

So from 00000H to 4 locations: 00000H to 00003H


Contents of 00001H and 00000H will be copied to new IP
Contents of 00003H and 00002H will be copied to new CS
PA of next instr = new CS x 10H + new IP
That program will be called as “ISR”
4.5 Interrupt Instructions

Ex: INT 01H


VIT BHOPAL UNIVERSITY

CS = 0000H
IP = type*4 = 01H x 4 = 0004H
PA is = CS x 10H + IP = 0000H x 10H + 0004H = 00004H

So from 00004H to 4 locations: 00004H to 00007H


Contents of 00005H and 00004H will be copied to new IP
Contents of 00007H and 00006H will be copied to new CS
PA of next instr = new CS x 10H + new IP
That program will be called as “ISR”
4.5 Interrupt Instructions

Like this, 00H to FFH types = 256 types


VIT BHOPAL UNIVERSITY

Each type will point 4 memory location


So, 256 x 4 memory locations = 1024 = 1KB
So initial 1KB = 00000H to 003FFH is called as
Interrupt Vector Table [IVT], this is reserved in
8086!
Interrupt Vector Table [IVT]
VIT BHOPAL UNIVERSITY
VIT BHOPAL UNIVERSITY Interrupt Vector Table
256 Interrupts of 8086 are Divided into 3 Groups

1. Type 00 to Type 04 interrupts


These are used for fixed operations and hence are
VIT BHOPAL UNIVERSITY

called dedicated interrupts

2. Type 05 to Type 31 interrupts


Not used by 8086,reserved for higher processors like 80286
80386 etc.

3. Type 32 to Type 255 interrupts


Available for user, called user defined interrupts. These can
be either H/W interrupts and activated through INTR
line or can be S/W interrupts.
Type – 0 :- Divide by Zero Error Interrupt
Quotient is large, cant be fit in AL/AX or divide by zero
Type –1:- Single step or Trap Interrupt
VIT BHOPAL UNIVERSITY

Used for executing the program in single step mode by setting trap flag.

Type – 2:- Non-Maskable Interrupt


This interrupt is used for executing ISR of NMI pin (positive edge signal),
NMI can’t be masked by S/W.

Type – 3:- One-byte INT instruction interrupt


Used for providing break points in the program
Type – 4:- Over flow Interrupt
Used to handle any overflow error after signed arithmetic.
String Prefix's

Prefix Condition for Exit Condition for


VIT BHOPAL UNIVERSITY

repeat
REP CX=0 CX=! 0
REPE / REPZ CX=0 and ZF=0 CX=! 0 and ZF=1
REPNE / REPNZ CX=0 and ZF=1 CX=! 0 and ZF=0
Example: String scan
Q: you need to scan a string to search existence of 10H and you
need to identify how many times 10H present in the string.
VIT BHOPAL UNIVERSITY
VIT BHOPAL UNIVERSITY

You might also like