Instructions Set 8086
Instructions Set 8086
• Examples:
OUT 81H, AL
OUT DX, AX
• XLAT: Translate a byte in AL
• General form: XLAT
• This instruction is used to translate a byte from one code to another code.
• It replaces a byte in AL register with a byte pointed by BX in a lookup table in
memory.
• Before using this instruction lookup table must be present in memory.
Starting address of table is loaded in BX register. The byte to be translated is
loaded in AL.
• AL -> DS : [ BX + AL ]
• The value in AL is added to BX. This new value will be used as pointer in data
segment.
• From the location, pointed by [BX+AL], data will be transferred to AL.
• Examples:
• ADD AL, 67H
• ADD DX, BX
• ADC: Add with Carry
• General form: ADC destination, source
• The operation of this instruction is same as ADD instruction except it
adds carry flag bit to the result.
• If CF=1 (set), 1 is added to the addition result.
• If CF=0 (reset), 0 is added to the addition result.
• All condition flags are affected by this instruction.
• Examples:
• ADC AX, BX
• ADC AH, 67H
• ADC BX, [SI]
• SUB: Subtract
• SBB: Subtract with Borrow
• General form: SUB destination, source
• destination.
• In case of SUB, only source will be subtracted from destination and result is placed
in destination.
• In case of SBB, borrow flag (i.e. carry flag) and source will be subtracted from
destination and result is placed in destination.
• DEC CL
• DEC AX
• CMP: Compare
• General form: CMP destination, source
• i) Let AL = 53, CL = 29
• ADD AL,CL; 7C
• DAA ; C > 9
• 7C + 06 = 82
• ii) Let AL = 73, CL = 29
• ADD AL,CL; 9C
• DAA ; C > 9
• 9C + 06 = A2
• A>9
• A2 + 60 = 02 in AL and CF = 1
• DAS: Decimal Adjust after Subtraction
• General form: DAS
• This instruction is used after subtracting two packed BCD numbers. The result of subtraction must be
in AL.
• If lower nibble of AL > 9 or the AF = 1 then this instruction will subtract 6 from lower nibble of AL.
• If the result in upper nibble is now greater than 9 or if carry flag was set, the instruction will subtract
60 from AL.
• Examples:
• 1) Let AL = 75, BH = 46
• SUB AL, BH ; AL = 75 – 46
• = 2F
• DAS ; AL = AL - 06
• = 2F - 06
• = 29
• 2) Let AL = 49, BH = 72
• SUB AL, BH ; AL = 49 - 72
• = D7 with CF = 1
• Since D > 9
• AL = AL - 60
• = D7 - 60
• = 77 with CF = 1
• NEG: Negate (Find 2’s complement)
• General form: NEG destination
• This instruction finds 2’s complement of
destination
• For finding 2’s complement, it subtracts the
contents of destination from zero.
• The result is stored in destination.
• The destination may be a register or a memory
location.
• MUL: Unsigned multiplication of byte or word
• General form: MUL source
• This instruction multiplies an unsigned byte by contents of AL or an
unsigned word by contents of AX.
• The source can be a register or memory location. Immediate data
cannot be used as source.
• When a byte is multiplied by AL, the result is put in AX.
• When a word is multiplied by AX, the result can be as large as 32
bits. The most significant word (upper 16 bits) of result is placed in
DX. The least significant word (lower 16 bits) of result is placed in AX.
• Examples:
• MUL BH ; AX = AL * BH
• MUL CX ; DX : AX = AX * CX
• IMUL: Multiply signed numbers
• General form: IMUL source
• This instruction multiplies a signed byte by AL or a signed word by contents of AX.
• The source can be a register or memory location. Immediate data can not be used
as source.
• When a byte is multiplied by AL, the signed result is put in AX.
• When a word is multiplied by AX, the signed result is put in registers DX and AX
with upper 16 bits in DX and lower 16 bits in AX.
• If upper byte of 16 bit result or upper word of 32 bit result contains only sign bits
(all 0s for positive result and all 1s for negative result) then CF = OF = 0 (reset).
• If upper byte of 16 bit result or upper word of 32 bit result contains part of the
product, CF = OF = 1 (set).
• AC, P, S, Z flags undefined.
• Examples:
• IMUL BX
• IMUL AX
• CBW: Convert signed Byte to signed Word.
• General form: CBW
• This instruction copies the sign bit of a byte in AL to
all bits in AH.
• No flags are affected.
• Examples:
• DIV BL ; AX / BL
• DIV CX ; DX : AX / CX
• IDIV: Signed division
• General form: IDIV source register or memory
• This instruction is used to divide a signed word by a signed byte or a signed
double word by a signed word.
• When a signed word is divided by signed byte, the word must be in AX. After
division, AL will contain signed result (quotient) and AH will contain signed
remainder.
• If a number is divided by zero or if result is greater than 127 or result is less
than -127, type 0 interrupt is generated.
• When a signed double word is divided by a signed word, the most significant
word must be in DX and least significant word must be in AX. After division,
AX will contain the 16 bit result and DX will contain 16 bit remainder.
• If a number is divided by 0, or if the result is greater than 7FFFH, or if the
result is less than 8001H, type 0 interrupt is generated.
• All flags are undefined.
• IDIV BL
• IDIV BP
• AAA: ASCII Adjust after Addition
• General form: AAA
• This instruction is generally used after an ADD instruction. AH must be
cleared before ADD operation.
• This instruction converts the contents of AL to unpacked decimal digits
(equivalent ASCII code).
• This instruction examines the lower 4 bits of AL whether it contains a
value in the range 0 to 9.
• If it is between 0 – 9 and AF=0, this instruction sets 4 higher bits of AL to
zero.
• If lower 4 bits of AL are in the range 0 – 9 and AF=1, 06H is added to AL.
The upper four bits of AL are cleared and AH is incremented by 1.
• If lower nibble (lower 4 bits) of AL is greater than 9, AL is incremented
by 6 and AH is incremented by 1. The upper nibble of AL is cleared and
AF=CF=1.
• Flags affected: A, C
• Examples:
1) Let BL = 34H ;ASCII code 4 and decimal 52
AL = 33H ; ASCII code 3 and decimal 51
then
ADD AL, BL ; AL = 33 + 34 = 67H
AAA ; AL = 07H ; ASCII CODE 7(ASCII 3 + ASCII 4)
• Examples:
• OR BX, CX
• OR AL, DL
• OR [BX], AH
• OR AL, 30H
• XOR: Logical Exclusive OR
• General form: XOR destination, source
• This instruction performs logical exclusive OR operation on bits of source and
destination. The result is stored in destination.
• The source can be immediate number, a register or memory location.
• The destination can be a register or a memory location.
• Both operands cannot be memory locations.
• The size of operand must be same.
• Flags affected:
• OF = CF = 0 (reset)
• P, S and Z flags are modified.
• A (Auxiliary Carry) flag is undefined.
• Examples:
• XOR AL, BL
• XOR CX, DX
• XOR BX, 5000H
• XOR [SI], FFH
• NOT: Invert each bit of operand
• General form: NOT destination
• This instruction complements the contents of
destination.
• The destination can be register or memory
location.
• No flags are affected.
• Examples:
• NOT BX
• TEST: AND operands to update flags.
• General form: TEST destination, source
• This instruction logically ANDs the bits of source and
destination.
• No operand will change, only flags are updated.
• Flags affected:
• OF = CF = 0 (reset)
• P, S and Z flags are modified.
• A (Auxiliary Carry) flag is undefined
• Examples:
• TEST AX, BX
• TEST [0500H], 06H
• TEST AL, CL
Shift / Rotate instructions
• SHL: Shift operand bits Left
• SAL: Shift Arithmetic Left operand bits
• General form: SHL destination, count
• SAL destination, count
• These instructions shift the destination bits to the left.
• Zero is inserted at the least significant bit position (i.e. bit
0). Most Significant Bit is transferred to Carry flag.
• Destination can be a register or a memory location.
• The count can be 1 or specified by register CL.
• Flags affected, AC flag is undefined.
•
• SHR: Shift Right
• General form: SHR destination, count
• This instructions shift the destination bits to
the right.
• Zero is filled in the most significant bit
position. Least Significant Bit is transferred to
Carry flag.
• Destination can be a register or a memory
location.
• The count can be 1 or specified by register CL.
• Flags affected: A flag is undefined.
• SAR: Shift Arithmetic Right
• General form: SHR destination, count
• This instructions shift the destination bits to
the right.
• It inserts the most significant bit of operand in
new position.
• Destination can be a register or a memory
location.
• The count can be 1 or specified by register CL.
• Flags affected: A flag is undefined
• ROR: Rotate Right without carry
• General form: ROR destination, count
• This instruction rotates the bits of destination
to the right.
• The LSB is transferred to MSB as well as to
carry flag.
• The destination can be a register or a memory
location.
• The count can be 1 or specified by CL register.
• ROL: Rotate Left without carry
• General form: ROL destination, count
• This instruction rotates the bits of destination
to the left.
• The MSB is transferred to LSB as well as to
carry flag.
• The destination can be a register or a memory
location.
• The count can be 1 or specified by CL register.
• RCR: Rotate Right through Carry flag:
• General form: RCR destination, count
• This instruction rotates the bits of destination
to the right through Carry Flag (CF).
• The CF bit is transferred to MSB of
destination.
• The LSB is transferred to carry flag.
• The destination can be a register or a memory
location.
• The count can be 1 or specified by CL register.
• RCL: Rotate Left through Carry flag
• General form: RCL destination, count
• This instruction rotates the bits of destination
to left through Carry Flag (CF).
• The MSB of destination is transferred to carry
flag.
• The CF bit is transferred to LSB of destination.
• The destination can be a register or a memory
location.
• The count can be 1 or specified by CL register.
• String manipulation instructions
• REP: Repeat instruction prefix
• This is used as a prefix to other instructions.
The instruction to which REP prefix is used, is
executed CX times. At each iteration CX is
automatically decremented by 1.there are two
more repeat instruction prefix: REPE / REPZ
i.e. Repeat if equal/zero and REPNE / REPNZ
i.e. Repeat if not equal/not zero.
• MOVSB / MOVSW: Move String Byte or String Word
• General form: MOVSB or REP MOVSB
• This instruction copies a byte or a word from a location in the data
segment to a location in the extra segment.
• The offset of source byte/word in data segment must be in SI register.
• The offset of destination in extra segment must be in DI register.
• For multiple byte/multiple word moves, the number of elements to be
moved is put in CX register. It acts as counter.
• After a byte/word move, SI and DI are automatically adjusted to point
to next source and destination byte/word.
• If Direction Flag (DF) = 0, SI and DI will be automatically incremented by
1 for byte move (MOVSB) and incremented by 2 for word move
(MOVSW).
• If DF = 1, then SI and DI will be automatically decremented.
• No flags are affected.
• DS : SI ES : DI
• CMPSB / CMPSW: Compare String Byte or Word
• General form: CMPSB or REPE CMPSB
• CMPSW or REPE CMPSW
• This instruction is used to compare two strings of byte or word.
• The length of string is stored in CX register.
• One string is stored in data segment and its offset is stored in SI.
• Second string is stored in extra segment and its offset is stored in DI.
• Comparison is done by subtracting the byte/word of destination
from the byte/word of source. Neither source nor destination is
changed.
• All condition flags are affected.
• If DF = 0, after comparison SI and DI are automatically incremented
by 1 or 2 (for CMPSB 1, for CMPSW 2).
• If DF = 1, after comparison SI and DI are automatically decremented
by 1 or 2 (for CMPSB 1, for CMPSW 2).
• SCANSB / SCANSW: Scan a String Byte or
String Word.
• General form: SCASB or REPNE SCASB
• This instruction compares a byte in AL or
word in AX with a byte or word pointed to by
DI in extra segment.
• If DF = 0, then DI will be incremented.
• If DF = 1, then DI will be decremented.
• If a match is found in the string Zero flag is
set.
• LODSB / LODSW: Load String Byte into AL or
Load String Word in AX
• General form: LODSB or LODSW
• This instruction loads a byte/word into AL/AX
from contents of a string pointed to by DS : SI.
• SI is modified depending upon DF. If DF = 0, SI
is incremented and if DF=1, SI is decremented.
• No flags are affected.
• STOSB / STOSW: Store a Byte or Word in
String
• General form: STOSB or STOSW
• This instruction stores AL/AX contents to a
location in string pointed by ES : DI.
• DI is modified depending upon DF. If DF = 0,
DI is incremented by 1 for STOSB and
incremented by 2 for STOSW instruction.
• No flags are affected by this instruction.
Branch and control transfer instructions
• Unconditional branch instructions
• CALL: Call a procedure
• This instruction is used to transfer execution to a
subprogram or procedure (subroutine).
• There are two types of CALL: near and far
• A near CALL is a call to a procedure which is in the same
segment. The value of IP register is stored on stack when
call is executed.
• A far call is a call to a procedure which is in different
segment. When call is executed, value of CS and IP
registers is stored on stack.
• RET: Return from the procedure
• This instruction returns execution from a
procedure to the next instruction after call
instruction.
• If procedure is near procedure then value of
IP is restored from stack.
• If procedure is far procedure then value of IP
as well as CS is restored from stack.
• INT N: Interrupt type N
• General form: INT N
• N can be a value between 00H to FFH.
• When INT N is executed, N is multiplied by 4. the result
will be used as offset and value 0000H will be used as
code segment value.
• The address 0000 : N*4 will be used to find new values
of IP and CS in order to execute an Interrupt Service
Routine (ISR).
• Example: INT 21H
• 21H * 4 = 84H
• 0084H is an offset in CS = 0000H.
• INTO: Interrupt on Overflow
• General form: INTO
• This instruction is executed when OF=1. the
address of ISR is found (i.e. value of CS and IP)
from memory location 0000 : 0016. this is
equivalent to INT 04H.
• JMP: Unconditional jump
• This instruction unconditionally transfers the control
of execution to specified address.
• If control is transferred within same code segment it
is called near jump or intra segment jump.
• If control is transferred to another code segment, it is
called far jump or inter segment jump.
• No flags are affected.
• Examples:
• LOOPNE / LOOPNZ:
• Loop while CX ≠ 0 and ZF = 0 (reset)
• This instruction executes the loop when CX ≠ 0
and ZF = 0.
• If ZF becomes 1 or CX = 0, the loop is terminated
• Conditional branch instructions:
• These instructions transfer the execution
control to given label if some condition is
satisfied.
• The target address must be in the range -80H
to 7FH (or -128 to 127) bytes from branch
instruction.
• No flags are affected
• S. No. Instruction Operation
• 1 JZ / JE label Jump to label if ZF = 1
• 2 JNZ / JNE label Jump to label if ZF = 0
• 3 JS label Jump to label if SF = 1
• 4 JNS label Jump to label if SF = 0
• 5 JO label Jump to label if OF = 1
• 6 JNO label Jump to label if OF = 0
• 7 JP / JPE label Jump to label if PF = 1
• 8 JNP label Jump to label if PF = 0
• 9 JC label Jump to label if CF = 1
• 10 JNC label Jump to label if CF = 0
• 11 JBE / JNA label Jump to label if CF = 1 or ZF = 1
• 12 JNBE / JA label Jump to label if CF = 0 or ZF = 0
• 13 JL / JNGE label Jump if neither SF = 1 nor OF = 1
• 14 JNL / JGE label Jump if neither SF = 0 nor OF = 0
• 15 JLE / JNG label Jump to label if ZF = 1 or neither SF = 1 nor OF = 1
• 16 JNLE / JG label Jump to label if ZF = 0 or at least any of SF & OF is 1
• 17 JCXZ label Jump to label if CX = 0
Flag Manipulation Instructions
• Flag manipulation instructions :These instructions are used
to control the processor action by setting/resetting the flag
values.
• STC − Used to set carry flag CF to 1
• CLC − Used to clear/reset carry flag CF to 0
• CMC − Used to put complement at the state of carry flag CF.
• STD − Used to set the direction flag DF to 1
• CLD − Used to clear/reset the direction flag DF to 0
• STI − Used to set the interrupt enable flag to 1, i.e., enable
INTR input.
• CLI − Used to clear the interrupt enable flag to 0, i.e.,
disable INTR input.
Machine control instructions
• HLT Halt processing. It stops program
execution.
• NOP Performs no operation.
• WAIT When WAIT instruction is executed,
the processor enters an idle state in which the
processor does no processing.
• LOCK It is a prefix instruction. It makes the
LOCK pin low till the execution of the next
instruction