Beruflich Dokumente
Kultur Dokumente
Similar to the instruction set of 8085, 8086 also has an instruction set which comprises of equivalent
instructions as in 8085 and other extra instructions such as multiplication, division and string operations.
The 8086 has 117 different instructions and about 300 op-codes. One important thing to be noted is that
no memory to memory instructions are allowed in 8086 except for string instructions. The instruction set
of 8086 can be classified into the following main categories for easy understanding:
There are totally 14 data transfer instructions which help in moving 16 bit or 8 bit data between registers
and I/O ports. The following table __ reveals the same.
POP AX Contents from top of stack moved to AX Moves the top word
from the stack to a
POP ES Contents from top of stack moved to ES destination. After this,
SP is incremented by 2.
POP [DI] Contents from top of stack moved to POP CS is not possible.
location specified by [DI]
PUSH DX Contents from DX moved to top of stack PUSH instruction
copies the contents of
PUSH DS Contents from DS moved to top of stack the specified location
to the top of stack.
PUSH [CX] Contents from location specified by [CX]
After this, SP
moved to top of stack
decrements by 2.
PUSH CS can’t be executed.
LEA AX, START Offset address of START in the data segment LEA (Load effective
is stored in AX. Assume START is a memory address) puts the
location. offset address of the
source into the
LEA DX, [BX] [SI] Contents of the locations denoted by [BX] specified register.
and [SI] are added and stored in CX.
LDS SI, [1234H] Contents of location denoted by offset LDS copies a word from
1234H in Data segment to lower byte of SI a memory location into
and similarly that of 1235H to higher byte of a register and next
SI. Contents of location denoted by offset memory location to DS
1236H in data segment to lower byte of DS register. Usually used
register and that of 1237H to higher byte of to initialize SI and DS
DS register. registers while starting
a string before using
any of the string
instructions.
IN AL, 18H 8 bit data from port 18H is stored in AL. Fixed port addressing.
Access to up to 256
IN AX, 18H 16 bit data from ports 18H and 19H will be ports.
stored in AX.
Variable port
Assume [DX] = 1234H. 8 bit data from port addressing. Access to
IN AL, DX 1234H is stored in AL. up to 65536 ports.
Note:
1. In fixed port addressing, we have to change the program for different ports. This is where
variable port addressing is helpful. We can write a general subroutine and supply the
address of the port to DX register. This way the port addresses can be changed
dynamically in a program itself.
2. No data transfer instruction affects the flag register except the SAHF and POPF
instructions.
ARITHMETIC INSTRUCTIONS
There are totally 19 arithmetic instructions which help in performing mainly addition, subtraction,
multiplication and division operations. The following table __ reveals the same.
ADD AL, 20H 20H is added with value in AL; result in AL. The general format of
the ADD instruction is
ADD DX, 1234H 1234H is added with value in DX; result in DX ADD destination,
source. Both
ADD AX, BX Contents of AX and BX are added and result
destination and source
stored in AX.
can’t be memory
Content of BL is added to the byte at memory locations, i.e.,
ADD BL, [CX] location pointed to by CX and result stored in BL. ADD [AX], [BX] is not
possible.
ADC DX, [BX] Assume [DX] = 0010H, [BX]= 0200H, [DS]= 2000H, ADC adds the data in
[CF]=1 and [20200]= 0050H. the source and
destination plus the
After executing the instruction, content of the carry
flag and stores the
[DX] = 0010 + 0050 + 1 = 0061H. result in the
destination. All the
All the possible operands of ADD instruction are rules of ADD
applicable to ADC also. instruction hold good
for ADC instruction.
SUB AL, 20H 20H is subtracted from value in AL; result in AL SUB subtracts data in
the source from the
SUB DX, 1234H 1234H is subtracted from value in DX; result in DX data in the destination
and stores result in
SUB AX, BX Content of BX subtracted from that of AX and
destination. The
result in AX.
general format is
Content of byte at memory location pointed by SUB destination,
SUB BL, [CX] CX subtracted from BL and result in BL. source. Both
destination and source
can’t be memory
locations, i.e., SUB
SUB BX, [DI] Content of value at the location pointed to by DI [AX], [BX] is not
subtracted from BX and result in BX. possible.
Content of DL is subtracted from the byte pointed The data of the
SUB [AX], DL
by AX and result stored in the location pointed by destination and the
AX. source must be of
same type: byte or
word. Flags AF, CF, OF,
PF, SF and ZF are
affected by SUB
instruction. The CF flag
acts as the borrow flag.
If the result is negative,
CF is set, else reset.
SBB DX, [BX] Assume [DX] = 0100H, [BX]= 0200H, [DS]= 2000H, SBB subtracts the data
[CF]=1 and [20200]= 0050H. in the source and the
value of CF from the
After executing the instruction, data in the destination
and the result is stored
[DX] = 0100 - 0050 - 1 = 00AFH. All the possible in destination. All the
operands of SUB instruction are applicable to SBB rules of SUB instruction
also. hold good for SBB
instruction.
NEG AL 2’s complement of value in AL stored in AL. NEG replaces the data
in the specified register
NEG BX 2’s complement of value in BX stored in BX. or memory location
with its 2’s
NEG BYTE PTR [CX] 2’s complement of the byte in memory pointed
complement. The data
by CX stored in the same memory location.
can be a byte or word.
2’s complement of the word in memory pointed All flags are affected by
NEG WORD PTR [SI] by SI stored in the same memory location. this instruction.
IMUL CL Multiply AL with CL. Product stored in AX. IMUL is used for signed
multiplication, i.e. if
IMUL AX Multiply AX with AX. Product stored in DX: AX. the magnitude of the
product does not
IMUL BYTE PTR [CX] Multiply AL with byte in memory pointed by CX.
require all the bits of
Product stored in AX.
the destination, these
Multiply AX with word from memory pointed by unused bits are filled
IMUL WORD PTR [SI] SI. Product stored in DX: AX. with the signed bit
value.
Note:
1. To multiply a signed byte by a signed word, the byte must be moved into a word location
(say BL) and the upper byte BH must be filled with copies of the signed bit using the
instruction CBW (Convert byte to word). Now BX contains the 16 bit sign extended bit.
2. If the upper byte of a 16 bit result or upper word of a 32 bit result contains only copies of
the sign bit (all 0’s or all 1’s) then CF =0, OF=0. If not, both will be 1. Other flags such as
AF, PF, SF and ZF are undefined after IMUL operation.
IDIV WORD PTR[BX] Assume [BX]= 0020H , [DS] = 1000H , IDIV is used for signed
division. The format
[10020H] = 0004H, [DX][AX] = 00000011H. and rules of this
instruction is same as
After the instruction, that of DIV instruction
only. Quotient is a
[DX] = 0001H (remainder) signed no. and the sign
of the remainder is the
[AX]= 0004H (quotient)
sign of the dividend.
Note:
1. To divide a signed byte by a signed byte, the dividend byte must be moved into AL and
the sign bit of the data in AL is extended to AH using the instruction CBW (Convert byte
to word). Now AX contains the 16 bit sign extended bit. To divide a signed word by a
signed word, the dividend must be moved into AX and the sign bit of the data in AX is
extended to DX: AX using instruction CWD (Convert word to double word).
2. If division by zero occurs or if the quotient is above FFH in 8 bit division or above FFFFH
in 16 bit division, then 8086 generates a type 0 interrupt. All flags are undefined after DIV
and IDIV operation.
3. This is for a faster recap of what you must mainly remember in DIV instruction.
Note:
1. In the above example shown, adding 5 and 6, gives a decimal result of 11. Its unpacked BCD form
is 0101H. This is stored in AX. When this result is to be sent to a printer, the ASCII code of each
decimal digit is found by adding 30H to each byte. This is done because the ASCII codes for
numbers 0 to 9 are 30H through 39H and only ASCII values are received by 8086 microcontroller
from a terminal.
2. An unpacked BCD number is represented as an 8 bit number in which the upper four bits
are always zero. For example, the decimal digit 5 is written as 05H in unpacked BCD
form.
There are totally 12 bit manipulation instructions which help in performing logical, shift and rotate
operations. The following table __ reveals the same.
AND AX, BX The corresponding bits of AX and BX are logically The general form of
ANDed and result stored in AX. the instruction is AND
destination, source.
AND performs a logical
AND operation
The operands can be either byte or words. Source
between source and
can also be immediate values.
destination and stores
the result in the
destination. PF, SF and
ZF are affected by this
instruction whereas CF
and OF remain zero.
OR AH, CH The corresponding bits of AH and CH are logically The general form is the
ORed and result stored in AH. same as that of AND
instruction. OR
performs a logical OR
operation between
The operands can be either byte or words. Source
source and destination
can also be immediate values.
and stores the result in
destination. Same flags
are affected as for AND
instruction.
XOR BH, DL The corresponding bits of BH and DL are logically The general form is the
ORed and result stored in BH. same as that of AND
instruction. XOR
performs a logical XOR
operation between
The operands can be either byte or words. Source
source and destination
can also be immediate values.
and stores the result in
destination. Same flags
are affected as for AND
instruction.
NOT [BX] Perform 1’s complement of the value in memory The general form of
pointed by BX. the instruction is NOT
destination. NOT
The operands can be either byte or words. instruction performs
1’s complement (or
inverts) of each bit of
the destination
specified. The result is
stored in the
destination itself. This
instruction does not
affect any flags.
TEST AH, FFH Assume AH= 00H. The general form is the
same as that of AND
After the instruction : TEST AH, FFH instruction. TEST
instruction ANDs the
AH=00H. ZF=1, PF=1, SF=0.
content of the source
with content of
destination. It is
The operands can be either byte or words. The different from AND
source can also be immediate values. instruction in the sense
that it does not store
the result anywhere.
Only the flags get
affected. Same flags
are affected as for AND
instruction.
SHL /SAL The operands can be either byte or words. SHL refers to logical
shift left, SAL means
shift arithmetic left.
Both these instructions
have the same
function. SAL is
generally used for
signed data only. The
general format of this
instruction is
SAL/ SHL destination,
count. This instruction
shifts each bit of the
destination to the left
by that many number
of times specified in
count. This count is
stored in register CL. If
the count is 1, it can be
directly specified in the
instruction.
STRING INSTRUCTIONS
There are totally 10 string instructions which help to move, scan or compare strings, bytes or words. All
string instructions do not have any operands. The following table __ reveals the same.
CMPSB / CMPSW Assume [ES] = 1000H, [DI] = 0002H, [DS] = 500H, This instruction
[SI] = 0006H, DF = 0. compares bytes or
words. CMPSB
After the instruction: CMPSB compares strings by
subtracting byte in
Flags get affected based on the result from
extra segment pointed
[50006] – [10002].
by DI from the byte at
[DI] = 0004H, [SI] = 0008H. Data segment pointed
by SI. The flags are only
affected. The contents
do not get affected.
SCASB/ SCASW Assume [ES] = 5000H, [DI] = 0002H, DF = 1, SCAS refers to scan
[50002] = FFH, [AL] = FFH. string. This instruction
is same as the above
After the instruction: SCASB but the only difference
is that here the string
[DI] =0001H{Since byte operation, decrease by 1}
is compared with AX,
ZF =1. { Since [AL] – [50002] = 00H } i.e. , the byte or word
in extra segment
Here, DI alone decrements or increments. SI pointed by DI is
remains unaffected. subtracted from the
byte in AL or word in
AX respectively.
BRANCH INSTRUCTIONS
As you have seen in 8085, there are different types of branching instructions available in 8086 also.
These vary from branching conditionally and unconditionally to calling or returning from a subroutine.
JMP instructions are different from CALL instruction in the sense CALL must be ended by a RET
instruction, whereas JMP instruction does not require a RET instruction.
JMP memory Contents of the next two words are moved to IP Unconditional
and CS respectively. branching: These
instructions can
This signed 8 bit data is added to [IP + 2]. [CS] is transfer control either
JMP 8 bit data not changed. within a same segment
JMP 16 bit data or outside a segment.
This unsigned 16 bit data is added to [IP + 2]. [CS]
Note that for
is not changed.
intersegment jumps,
Content of the register is moved to [IP]. [CS] is not both CS and IP
JMP register changes. For
changed.
intrasegment changes,
CS remains constant
CALL memory / CALL 8 Call function can also be used with all of the but IP will change.
bit data / CALL 16 bit above operands. The function of this instruction
data / CALL register is same as JMP. But CALL is generally used to call
subroutines.
If a condition is true,
JNS 8-bit data Jump if result is positive. (SF=0) PC= PC + displacement
address.
JP 8-bit data Jump if parity produced. (PF=1)
If condition is false,
JNP 8-bit data Jump if parity not produced. (PF=0) PC = PC + 2. The next
instruction is executed.
JPO 8-bit data Jump if parity is odd. (PF=0)
2. For comparing two unsigned or signed numbers, use the following instructions after
the compare instruction. Generally we use the terms ‘above’ and ‘below’ for unsigned
numbers and ‘greater’ or ‘lesser’ for signed numbers.
JNE 8-bit data Jump if not equal, i.e. AX ≠ BX (ZF=0) JNE = JNZ
JG 8-bit data Jump if greater, i.e. AX > BX (ZF=0 & SF =0) JG = JNLE
JGE 8-bit data Jump if greater or equal, i.e. AX ≥ BX (SF=OF) JNG = JLE
JLE 8-bit data Jump if lesser or equal, i.e.AX≤BX (ZF=1 or SF≠OF) JNL= JGE
JNG 8-bit data Jump if not greater, i.e. AX≤BX (ZF=1 or SF≠OF) JP = JPE
JNGE 8-bit data Jump if not greater or equal, AX < BX (SF ≠ OF) JNP = JPO
JNLE 8-bit data Jump if not lesser or equal, i.e. AX > BX (ZF=0 & SF
=0)
LOOP 8-bit data Decrement CX and jump to the specified address Iteration Control
if CX ≠ 0. Instructions: The
general function of
Loop if equal. (While CX≠0 and ZF=1) each instruction is that
LOOPE 8-bit data/
they decrement CX
LOOPZ 8-bit data
register by 1 and act
LOOPNE 8-bit data/ Loop if not equal. ( While CX≠0 and ZF=0) similar to JMP
LOOPNZ 8-bit data instruction if CX ≠ 0.
None of the flags are
JCXZ affected. If CX = 0, then
Jump if register CX = 0. the loop ends and the
next instruction is
performed.
The interrupt related instructions are also a type of branching instruction as the
control jumps to another place in memory where the interrupt service routine is executed. These
instructions can create only software interrupts (interrupts which can be created by
programming).
INT number The number here can be anything between 00H Totally 256 interrupts
and FFH. Upon this instruction, 8086 executes the can be generated. But
interrupt service routine for that particular out of these, only
interrupt. interrupt numbers 20H
to FFH are available to
the user.
Their name itself explains their meaning clearly. All instructions except ‘ESC’ have no operands.
LOCK A low signal is produced on the LOCK pin of 8086 This instruction locks
during the next instruction. the system bus, i.e.,
the processor will not
be able to use the
system bus for the next
instruction. This
instruction is used
while multiprocessing.
The LOCK works only
with XCHG, ADD, ADC,
SUB, SBB, OR, AND,
XOR, NOT, NEG, INC
and DEC instructions
having a memory
operand.
HLT The processor goes into halt state. HLT refers to halt. This
instruction stops
execution of all
instructions. Only a
reset signal or an
interrupt signal can
make the processor
resume execution from
halt state.
STI Interrupt enable flag is set. (IF=1) STI refers to Set the
interrupt enable flag.
CLI Interrupt enable flag is cleared. (IF=0) CLI refers to clear the
interrupt enable flag.
WAIT This instruction checks if the TEST pin of 8086 is This instruction does
high or low. If the pin is high, then 8086 enters not affect any flags.
into an idle state where no execution takes place. During the idle state, if
a valid interrupt is
If the TEST pin is made low or a higher interrupt is encountered, the
encountered, then 8086 comes out of this idle interrupt is serviced
state. and 8086 goes back to
the idle state. This
instruction when used
before the ESC
instruction; makes
8086 do other
processes while a
coprocessor (like 8087)
is executing an
instruction.
ESC memory_address The contents of the memory_address are placed ESC refers to escape to
on the data bus when the READY pin is made high external processor. This
by the external processor. By doing so, 8086 instruction acts as a
triggers the external processors. trigger to operate the
external processors.
ASSEMBLER DIRECTIVES
As we all know, an assembler converts the assembly language program into the machine language
program. For assembling the program to machine language, the assembler needs certain commands;
maybe to indicate the storage space required for a particular variable so that it creates the required
space or the name of the segments (CODE, DATA, EXTRA and STACK), etc. Such commands are called
directives. These directives are predefined and help the assembler to correctly convert the assemble
language into machine language.
ORG 20H If ORG is inside code segment, then the first instruction is
stored at an offset 20H in the code segment. If ORG is inside
data segment, then data storage starts at an offset 20H in
the data segment. If no ORG is mentioned, then everything
begins at 00H.
2) To define the size of a variable: DB (define byte) ; DW( define word) ; DD (define double word);
DQ (define quad word) and DT (define ten bytes) .
SRIRAM DB 50H One byte is reserved for variable SRIRAM. Value of 50H is
assigned to SRIRAM.
DELHI DW 1000H One word is reserved for variable DELHI. 1000H is initialized
to DELHI.
SRIRAM DB 02H, 04H, 06H Three bytes reserved for variable SRIRAM. Values of 02H,
04H and 06H assigned to SRIRAM.
CHENNAI DB 100 DUP (10H) 100 bytes reserved for array CHENNAI, each element
initialized to 10H.
TRAIN DW 50 DUP (?) 50 words reserved for array TRAIN, each element having no
value initialized.
ASSUME CS: PROGRAM, DS: DATA, SS: STACK This makes the assembler understand that
PROGRAM is CS which contains instructions;
DATA is DS which contains the data and STACK is
SS which contains the stack.
The above instruction set covers all instructions required to become a confident programmer in
8086. Along with the instruction set, simultaneously go through the sample programs for clearer
understanding.