Vous êtes sur la page 1sur 34

Chapter 6 - 8086 instruction

description and assembler


directives
from Microprocessors and Interfacing by
Douglas Hall

Outline
Instruction Description
Assembler Directives

Instruction Description(contd.)
AAA ASCII Adjust for Addition
8086 allows you to add ASCII codes for two decimal digits
without masking of the 3 in upper nibble of each.
After the addition, the AAA instruction is used to make sure
that the result is the correct unpacked BCD.
The AAA instruction works only on AL register.
AAD BCD to binary convert before Division
Converts two unpacked BCD digits in AH and AL to the
equivalent binary number in AL.
After the Division the AL will contain the unpacked BCD
quotient and AH will contain the unpacked BCD remainder.

Instruction Description(contd.)
AAM BCD Adjust for Multiply
After the two BCD digits are multiplied the AAM instruction is
used to adjust the product to two unpacked BCD digits in AX.
Works only on an operand in AL.
Updates PF, SF and ZF.
AAS ASCII Adjust for Subtraction
8086 allows you to subtract ASCII codes for two decimal digits
without masking of the 3 in upper nibble of each.
After the subtraction, the AAA instruction is used to make
sure that the result is the correct unpacked BCD.
The AAS instruction leaves the correct unpacked BCD result in
the low nibble of AL.

Instruction Description(contd.)
ADC Add with Carry, ADD Addition
ADC source, destination: adds the number from source to the
number in destination and then stores the result in destination and
the carry in CF.
ADD source, destination: Does similar things as the ADC but
do not store the carry in CF. Rather it discards the carry.
AND
AND destination, source: ANDs each bit in the source byte or
word with each bit in the destination byte or word.
The result is put into specified destination register/location, the
contents of the source does not change.

Instruction Description(contd.)
CALL Call a procedure
Used to transfer the execution to another subprogram or
procedure. There are two basic types:
NEAR: a call to a procedure which is in the same code
segment as the CALL instruction.
FAR: a call to a procedure which is in different segment then
the CALL instruction.
CBW Convert signed Byte to signed Word
Copies the sign of a byte in AL to all the bits in the AH.
AH is then said to be the sign extension of the AL.
The CBW must be done before a signed byte in AL can be
divided by another signed byte with the IDIV instruction.

Instruction Description(contd.)
CLC, CLD, CLI, CMC
CLC: Instruction resets the carry flag to 0.
CLD: resets the direction flag to 0.
CLI: resets the interrupt flag to 0.
CMC: complement the carry flag i.e. from 01 and from 10.
CMP Compare byte or word
CMP destination, source: this instruction compares the byte
from the source to the byte in the destination or a word from the
specified source to the word from the specified destination.
Flags AF, OF, SF, ZF, PF and CF flags are updated to show the
result of the comparison.

Instruction Description(contd.)
CMPS/CMPSB/CMPSW Compare String Bytes or String Words
Used to compare a byte in one string with the byte in another string or a word in
one string with the word in another string.
SI is used to hold offset of source string and DI is used for the destination string.
CWD Convert signed Word to signed Double Word
Copies the sign bit of a word in AX to all the bits in the DX register.
It must be done before the signed word in AX is divisible by another signed word
with the IDIV instruction.
It affects no flags.
DAA, DAS
DAA: used to make sure the result of adding two BCD number is a BCD number.
DAS: used after subtracting two BCD numbers to make sure the result is correct
packed BCD.

Instruction Description(contd.)
DEC Decrement Destination register or memory
DEC destination: subtracts one from the destination word
or byte.
AF, OF, PF, SF and ZF flags are updated.
DIV Unsigned Divide
Used to divide unsigned word by a byte or to divide an
unsigned double word by a word.
The word must be present in AX register and divisor must be
in register or memory location.
After division AL contains the 8-bit result (quotient) and AH
will contain the 8-bit remainder.

Instruction Description(contd.)
ESC Escape
Used to pass instructions to the coprocessor such as 8087 math
processor shares the address and data bus with an 8086.
HLT Halt processing
It causes 8086 to stop fetching and executing instructions.
Processor will be in the halt state. The only way it can be resume is by
generating interrupt at the INTR pin.
IDIV Divide by signed byte or word
IDIV source: the instruction is used to divide a signed word by a
signed byte, or to divide signed double word by a word.
The operand must be in AX the divisor may be in register or memory
location.
The final quotient is stored in AL and remainder will be stored in AH.

Instruction Description(contd.)
IMUL Multiply signed numbers
IMUL source: multiplies a signed byte from some source times a
signed byte in AL or a signed word from some source times a signed
word in AX.
CF and OF flags are updated.
IN copy data from a port
IN Accumulator, port: copy data from a port to the AL or AX register.
If 8-bit port is read then the data will be read into AL else if 16-bit port
is read the data will go into AX.
INC Increment
INC Destination: it adds one to the source word or byte specified in
the destination.
AF, OF, PF, SF and ZF are affected.

Instruction Description(contd.)
INT Interrupt program execution
INT Type: type refers to any number between 0 to 255.
When 8086 executes the INT instruction it does following:

Decrement the stack pointer by 2 and PUSH the flags onto the stack.
Decrement the stack pointer by 2 and PUSH the contents of CS onto
the stack.
Decrement the stack pointer by 2 and PUSH the offset of the next
instruction after INT into the stack.
Get a new value for IP from an absolute memory address of 4 times the
type specified in the instruction.
Get a new value for CS from an absolute memory address of 4 times
the type specified in the instruction plus 2.
Reset both IF and TF.

Instruction Description(contd.)
INTO Interrupt on overflow
Decrement the stack pointer by 2 and PUSH the flags onto
the stack.
Decrement the stack pointer by 2 and PUSH the contents of
CS onto the stack.
Decrement the stack pointer by 2 and PUSH the offset of the
next instruction after INTO onto the stack.
Reset TF and IF.
IRET Interrupt Return
Use at the end of the interrupt service procedure to return
execution to the interrupted program.
It reloads the contents of the stack and changes the IP value.

Instruction Description(contd.)
JA/JNBE Jump if Above/Jump in Not Below or Equal
After compare or some other instruction the instruction will cause the
execution to jump to a label given in the instruction.
No flags are affected.
JAE/JNB/JNC Jump if Above or Equal/Jump if Not Below/Jump in No
Carry
If after a compare or some other instruction the CF is 0 this instruction
will cause the execution to jump on the specified label.
If CF is 1 the instruction will have no effect.
JB/JC/JNAE Jump if Below/Jump if Carry/Jump if Not Above or
Equal
If after a compare or some other instruction the CF is 1 this instruction
will cause the execution to jump on the specified label.
If CF is 0 the instruction will have no effect.

Instruction Description(contd.)
JBE/JNA Jump if Below or Equal/Jump if Not Above
If after a compare or some other instruction the CF is 1 this instruction will
cause the execution to jump on the specified label.
If CF and ZF both are 0 the instruction will have no effect.
JCXZ Jump if the CX register is 0
JE/JZ Jump if Equal/Jump if Zero
JG/JNLE Jump if Greater/Jump if Not Less than or Equal
After compare the instruction will cause a jump if ZF is 0 and CF is same as
the OF.
The destination must be in the range of -128 bytes to +127 bytes.
JL/JNGE Jump if Less than/Jump if Not Greater than or Equal
After compare instruction it will cause the jump if SF is not equal to OF.
The destination must be in the range of -128 bytes to +127 bytes.

Instruction Description(contd.)
JLE/JNG Jump if Less than or Equal/Jump if Not Greater
After compare instruction it will cause the jump if ZF is set or SF
is not equal to OF.
The destination must be in the range of -128 bytes to +127
bytes.
JMP Unconditional Jump to the Specified Location
It will always force the 8086 to jump to the specified location.
The more similar instructions are JNE Jump if Not equal, JNZ
Jump if Not Zero, JNO Jump if No Overflow, JNP Jump if No
Parity, JPO Jump if Odd Parity, JNS Jump if Not Signed, JO
Jump if Overflow, JP Jump if Parity, JPE Jump if Parity Even, JS
Jump if Signed etc.

Instruction Description(contd.)
LAHF Copy low byte of Flag register to AH
Lower byte of the 8086 is same as the flag bytes of the 8085.
Thus it copies the flag bytes of the 8085 to the AH register.
LDS Load register and DS with the word from memory
LDS Register, memory address of first word: it copies
the word from two memory locations into the register specified
in the instruction.
It then copies the word from the next two memory location into
DS register.
LEA Load Effective Address
LEA register, source: determines offset of the variable or
memory location named source and puts it into 16-bit register.

Instruction Description(contd.)
LES Load register and ES with the word from
memory
This instruction loads new values into the specified register
and ES register from four successive memory locations.
The word from the first two memory location will be copied
to the specified register and the word from the next two
locations will be copied in to the ES register.
LOCK Assert Bus lock Signal
Allows microprocessors to ensure that the other processor
cant take control of the system bus while it is in critical
instruction which uses the system bus.

Instruction Description(contd.)
LODS/LODSB/LODSW Load String word or byte into AL
Copies the byte from a string location pointed to by SI to AL or a word to
AX.
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.
MOV Copy a word or byte
MOV destination, source: copies a word or byte from the source byte
to the destination byte.
The variants are MOVS/MOVSB/MOVSW move string, byte or move
string word.

Instruction Description(contd.)
MUL Multiply unsigned bytes or words
MUL source: multiplies the unsigned byte from source times an
unsigned byte in the AL register or word in the AX register.
NEG Forms 2s complement
NEG Destination: replaces the number in destination with the 2s
complement of that number
NOP NO Operation
It simply uses the 3 clock cycles and increments the instruction pointer
to point to the next instruction.
OR Logically OR
OR Destination, Source: ORs each bit in source byte or word with the
bit in destination byte or word.
The result is put in the specified destination.

Instruction Description(contd.)
OUT Output a Byte or word to a port
OUT Port, Accumulator: the Out instruction copies a byte from AL
or a word from AX to the specified port.
Two types of ports: Fixed and Variable port
POP
POP destination: copies the word from the stack top location to the
destination specified.
The stack pointer is automatically incremented by 2.
PUSH
PUSH Source: decrements the stack pointer by 2 and copies the
word specified in the source to the location pointed by the stack
pointer.
PUSHF: push the flag register onto the stack.

Instruction Description(contd.)
RCL Rotate operand around to the left through CL
Rotates all the bits in the specified byte or word to some bits in left.
It is circular because the MSB of the operand is stored in to the CF and then CF is
stored in to the LSB of the operand.
Similarly RCR: rotates the operand through right using CF.
REP/REPE/REPNE/REPZ/REPNZ Repeat String Instruction until specified
condition exists
REP is the prefix which will cause the CX register to be decremented and the string to
be repeated until CX=0.
REPE is repeat is equal, REPZ is repeat if zero causes the string to be repeated as long
as the words are equal and ZF=1 respectively.
RET Return Execution from the procedure call
Return execution from the procedure to the next instruction after the CALL instruction.
It do this by restoring the stack contents to the registers and setting IP to point to the
next instruction after the CALL instruction.

Instruction Description(contd.)
ROL rotate Left, ROR Rotate Right
ROL Destination, count: rotate the bits specified in destination to count
no of bit positions.
Similarly ROR do the same thin but it rotates towards right.
SAHF- Copy AH register to low byte of Flag register
The lower byte of the 8086 flag register exactly corresponds to the 8085
flag register.
This instruction replaces this 8085 flag register with the byte from AH
register.
SAL/SHL Shift operand bit in left, put zero in LSBs, SAR shift
right
SAL/SHL Destination, count: shifts each bits in the specified destination
to some number of bits specified by the count value towards left.
SAR destination, count: shifts in right.

Instruction Description(contd.)
SBB Subtract with Borrow, SUB - subtract
SUB Destination, source: subtracts the number in source from the number in
destination and the final result is stored in destination. It ignores borrow.
SBB: it does the same thing but do not ignore borrow.
SCAS/SCASB/SCASW Scans a String or Byte or Word
Compares a byte in AL or a word in AH with a byte or word pointed to by DI in ES.
Therefore the string to be compared must be in extra segment and the DI must
contain the offset of the byte or word.
STC/STD/STI set carry flag, set direction flag, set interrupt flag to 1.
STOS/STOSB/STOSW Stores byte or word in string
Copies a byte from AL or a word from AX to the memory location in extra
segment pointed by DI.
After copy DI is automatically incremented or decremented to point to the next
string element in memory.

Instruction Description(contd.)
TEST AND operands to Update
ANDs the contents of the source byte with the contents of the
destination byte. Flags are updated but neither operand is
changed.
WAIT Wait for test signal or interrupt signal
8086 enters in idle condition and does no processing. It will stay
in the idle position until 8086 TEST input pin is made low or
interrupt signal is received on INTR or NMI pins.
XCHG
XCHG destination, source: changes the contents of
destination with contents of source and vice versa.
Destination and Source both must be either byte or word. It can
be register or memory location.

Instruction Description
XLAT/XLATB Translate a byte in AL
Used to translate a byte from one code to another code.
Replaces the byte in AL register with the byte pointed to by
BX in a lookup table in the memory. The lookup table must
be in the memory before execution of XLAT.
XOR eXclusive OR
XOR Destination, Source: instruction exclusive ORs each
bit in the source byte or word with the bit in the destination
byte or word.
The result will follow the truth table of XOR. The answer will
be stored in the destination.

Assembler Directives(contd.)
Assume
Used to tell the assembler the name of the logical segment it
should use for a specified segment.
You must tell the assembler that what to assume for any
segment you use in the program.
Example, ASSUME: CODE tells the assembler that the
instructions for the program are in segment named CODE.
DB Defined Byte
Used to declare a byte type variable or to set aside one or
more locations of type byte in memory.
Example, PRICES DB 49H, 98H, 29H: Declare array of 3 bytes
named PRICES and initialize 3 bytes as shown.

Assembler Directives(contd.)
DD Define Double Word
Used to declare a variable of type doubleword or to reserve a
memory location which can be accessed as doubleword.
DQ Define Quadword
Used to tell the assembler to declare the variable as 4 words
of storage in memory.
DT Define Ten bytes
Used to tell the assembler to declare the variable which is 10
bytes in length or reserve 10 bytes of storage in memory.
DW Define Word
Used to tell the assembler to define a variable type as word
or reserve word in memory.

Assembler Directives(contd.)
END End the program
To tell the assembler to stop fetching the instruction and end
the program execution.
ENDP it is used to end the procedure.
ENDS used to end the segment.
EQU Equate
Used to give name to some value or symbol.
EVEN Align on Even memory address
Tells the assembler to increment the location counter to the
next even address if it is not already at an even address.

Assembler Directives(contd.)
EXTRN
Used to tell the assembler that the name or labels following
the directive are in some other assembly module.
GLOBAL Declares symbols as PUBLIC or EXTRN
Used to make the symbol available to other modules.
It can be used in place of EXTRN or PUBLIC keyword.
GROUP Group related segment
Used to tell the assembler to group the logical segments
named after the directive into one logical segment.
This allows the content of all the segments to be accessed
from the same group.

Assembler Directives(contd.)
INCLUDE include source code from file
Used to tell the assembler to insert a block of source code from the
named file into the current source module. This shortens the source
code.
LABEL
Used to give the name to the current value in the location counter.
The LABEL directive must be followed by a term which specifies
the type you want associated with that name.
LENGTH
Used to determine the number of items in some data such as
string or array.

Assembler Directives(contd.)
NAME
Used to give a specific name to a module when the programs consisting
of several modules.
OFFSET
It is an operator which tells the assembler to determine the offset or
displacement of named data item or procedure from the start of the
segment which contains it.
ORG Originate
Tells the assembler to set the location counter value.
Example, ORG 7000H sets the location counter value to point to 7000H
location in memory.
$ is often used to symbolically represent the value of the location
counter. It is used with ORG to tell the assembler to change the location
according to the current value in the location counter. E.g. ORG $+100.

Assembler Directives(contd.)
PROC Procedure
Used to identify the start of the procedure.
PTR Pointer
Used to assign a specific type to a variable or a label.
It is necessary to do this in any instruction where the type of the
operand is not clear.
Public
It is used to tell the assembler that the specified label or
variable is accessible by other modules.
This is useful in large programs which are generally written in
modules.

Assembler Directives
SEGMENT
Used to indicate that the start of a logical segment.
Preceding the segment directive is the name you want to give to the
segment.
SHORT
Used to tell the assembler that only a 1-byte displacement is needed to
code a jump instruction.
If the jump destination is after the jump instruction in the program, the
assembler will automatically reserve 2 bytes for the displacement.
TYPE
Tells the assembler to determine the type of a specified variable.
The TYPE operator can be used in instruction such as ADD BX, TYPE
WORD_ARRAY, where we want to increment BX to point to the next word in
an array of words.