Sie sind auf Seite 1von 94

MOV destination, source

y Examples: y MOV BX,1234H y MOV CL,[1000H] y MOV AX,BX

PUSH source
y Decrements SP by 2 & copies a word from source in

stack. y Source must a word (16-bit). y Eg:


y PUSH CX y PUSH DS

POP destination
y Copies a word from stack to destination y SP is incremented by 2. y Eg: y POP CX y POP DS

XCHG destination, source


y Examples: y XCHG BX,CX y XCHG AL,CL

XLAT : Translate byte in AL


y Replaces a byte in AL register with a byte from a

lookup table in memory. y AL <- DS : [BX + AL]

LEA : Load Effective Address LEA register, source


y Determines the offset of the source & loads this

address in the specified register. y Eg:


y LEA CX, TOTAL y LEA AX, [BX] [DI]

LDS, LES
y Loads DS/ES & the specified destination register in the instruction with the contents of memory location specified as source in the instruction. y Eg: LDS BX, 5000H / LES BX,5000H

BX

YY

XX

XX YY

5000 5001 5002 5003

DS/ES

NN

MM

MM NN

LAHF: Load lower byte of flag register in AH


y Copies the contents of lower byte of 8086 flag

register to AH register.

SAHF: Copy AH register to lower byte of


flag register

PUSHF :
y Decrements the SP by 2 & copies the word in

the flag register to the memory location pointed by the SP

POPF:
Copies a word from the two memory locations at the top of stack to the flag register & increments SP by 2.

IN: Input a byte or word from port


y Copies data from a port to the accumulator. y If 8-bit port is read, the data will go to AL. y IN AL,F8H y IN AX,95H y In indirect addressing, the address of the port

is referred from DX register. y MOV DX,30F8H y IN AL,DX y IN AX,DX

OUT: Send a byte or word to port


y Copies data from a AL or AX to a port. y OUT F8H,AL y OUT FBH,AX y In indirect addressing, the address of the port

is referred from DX register. y MOV DX,30F8H y OUT DX, AL y OUT DX, AX

CBW (Convert Byte to Word)


y Copies the sign of a byte in AL to all the bits in AH. y AH is said to be sign extension of AL. y AX=0000 0000 1001 1000 = -152 decimal y CBW y AX=1111 1111 1001 1000 = -152 decimal

CWD (Convert Word to Double)


y Copies the sign of a word in AX to all the bits of DX. y DX is said to be sign extension of AX. y DX=0000 0000 0000 0000 y AX=1111 0000 1100 0001 = -28865 decimal y CWD y DX=1111 1111 1111 1111 y AX=1111 0000 1100 0001 = -28865 decimal y DX:AX together can be used for 32-bit operand

ADD/ADC destination, source


y ADD AL,30H y ADC DL,BL y ADD CX, [2048]

INC destination
y Adds 1 to specified destination. y INC BX y INC CL

AAA: ASCII Adjust for Addition


y The numbers from 0-9 are represented as 30H-

39H in ASCII code. y For addition of two decimal numbers represented in ASCII code, it is necessary to mask upper nibble(3) from code before addition. y 8086 allows you to add ASCII codes for two decimals without masking off 3. y AAA is used after addition to get the current result in unpacked BCD form.

AAA: ASCII Adjust for Addition


y AL = 0011 0100

ASCII 4 y CL = 0011 1000 ASCII 8 y ADD AL,CL ; AL = 0110 1100 y AAA ; AL = 0000 0010 unpacked BCD for 2 ; carry = 1 to indicate answer=12 decimal The AAA works only on the AL register.

DAA : Decimal Adjust Accumulator


y This instruction is used to make sure the result of

addition of two packed BCD numbers is adjusted to be a legal BCD number. y If the value of D3-D0 in the AL > 9 , or AF is set, the instruction adds 06 to D3-D0. y If the value of D7-D4 in the AL > 9 , or CF is set, the instruction adds 06 to D7-D4.

DAA : Decimal Adjust Accumulator


y AL = 0011 1001

BCD 39 y CL = 0001 0010 BCD 12 y ADD AL,CL ; AL = 0100 1011 = 4BH y DAA ; add 0110 because 1011 > 9 ; AL = 0101 0001 =51 BCD
The DAA works only on the AL register.

SUB/SBB destination, source


y SUB AL,30H y SBB DL,BL y SUB CX, [2046]

DEC destination
y Subtracts 1 to specified destination. y DEC BX y DEC CL

NEG: Forms 2 s complement


y Replaces the number in a destination with the 2 s

compliment of that number. y NEG AL

CMP destination, source


y Compares a byte/word from source with a byte/word

from destination. y The source & the comparison is done by subtracting source from destination. The result is not stored in destination. y Source & destination remain unchanged, only flags are updated. y CMP AL, 04H y CMP CX,BX

AAS : ASCII Adjust after Subtraction


y The numbers from 0-9 are represented as 30H-

39H in ASCII code. y For subtraction of two decimal numbers represented in ASCII code, it is necessary to mask upper nibble(3) from code before subtraction. y 8086 allows you to subtract ASCII codes for two decimals without masking off 3. y AAS is used after subtraction to get the current result in unpacked BCD form.

AAS : ASCII Adjust after Subtraction


y AL = 0011 0010

ASCII 2 y CL = 0011 1000 ASCII 8 y SUB AL,CL ; AL = 1111 1010 = FAH y AAS ; AL =0000 0110 =BCD 6 ; carry = 1 to indicate -6

CF=1

DAS : Decimal Adjust After Subtraction


y This instruction is used to make sure the result of

subtraction of two packed BCD numbers is adjusted to be a legal BCD number. y If the value of D3-D0 in the AL > 9 , or AF is set, the instruction subtracts 06 to D3-D0. y If the value of D7-D4 in the AL > 9 , or CF is set, the instruction subtracts 06 to D7-D4.

DAS : Decimal Adjust After Subtraction


y AL = 0011 0010

BCD 32 y CL = 0001 0111 BCD 17 y SUB AL,CL ; AL = 0001 1011 = 1BH y DAS ; subtract 0110 because 1011 > 9 ; AL = 0001 0101 =15 BCD
The DAS works only on the AL register.

MUL source
y Unsigned multiplication y When byte is multiplied by AL, the result is stored in

AX. y When word is multiplied by AX, the MSW of result is stored in DX & LSW of result is stored in AX. y MUL BL y MUL BX

IMUL source
y Signed multiplication y When byte is multiplied by AL, the result is stored in

AX. y When word is multiplied by AX, the MSW of result is stored in DX & LSW of result is stored in AX. y To multiply a signed byte by a signed word, it is necessary to move the byte into a word location & fill the upper byte of the word with copies of the sign bit. y IMUL BL y IMUL BX

AAM: BCD adjust after multiply


y After the two unpacked BCD digits are multiplied, the

AAM is used to adjust the product to unpacked BCD. y AL= 0000 0100 = unpacked BCD 4 y CL= 0000 0110 = unpacked BCD 6 y MUL CL ; AX=0000 0000 0001 1000 = 0018H y AAM ; AX=0000 0010 0000 0100 = 0204 H

DIV source
y Divide unsigned word by byte or unsigned double

word by word. y When dividing word by byte, word must be in AX. After division AL=Quotient & AH= Remainder. y When dividing double word by word, the MSW of double word must be in DX & LSW must be in AX. After division AX=Quotient & DX= Remainder. y If an attempt is made to divide by 0 or the quotient is too large to fit in AL/AX register, 8086 will execute a type 0 interrupt. y DIV CL y DIV CX

IDIV source
y Divide a signed word by a signed byte or a signed

double word by a signed word.

AAD: Binary Adjust before division


y Converts two unpacked BCD digits in AH & AL

to the equivalent binary number in AL. y This adjustment must be made before dividing the two unpacked BCD digits in AX by an unpacked BCD byte. y After division AL=unpacked BCD quotient, AH=unpacked BCD remainder.

AAD: Binary Adjust before division


y AX=0403 = unpacked BCD for 43 decimal y CL=07H y AAD ; adjust to binary before division AX=002BH y DIV CL ; AL=quotient= 06 unpacked BCD

; AH= remainder= 01 unpacked BCD

Bit Manipulation Instructions (Logical Instructions)

NOT destination
y Inverts each bit of a byte or a word. y AL= 0110 1100 y NOT AL ; AL=1001 0011

AND destination, source


y Logically ANDs each bit of the source byte or word

with the corresponding bit in the destination & stores result in the destination. y AL=1001 0011 =93H y BL=0111 0101 = 75H y AND BL,AL ; BL= 0001 0001 =11H

OR destination, source
y Logically ORs each bit of the source byte or word with

the corresponding bit in the destination & stores result in the destination. y AL=1001 0011 =93H y BL=0111 0101 = 75H y OR BL,AL ; BL= 1111 0111 =F7H

XOR destination, source


y Logically XORs each bit of the source byte or word

with the corresponding bit in the destination & stores result in the destination. y XOR BL,AL

TEST destination, source


y Logically ANDs contents of the source byte or word

with the contents of the destination. y Neither operand is changed. Flags are affected. y PF, SF, ZF will be updated to show the result of the ANDing. y TEST AL,CL y TEST AX,CX

SAL/SHL destination, count


y Shifts each bit in the specified destination to the left & 0 is stored at

LSB position. y MSB to carry flag. y Number of shifts are indicated by count. y SAL AX,1
CY 0

SHR destination, count


y Shifts each bit in the specified destination to the right & 0 is stored

at MSB position. y LSB to carry flag. y Number of shifts are indicated by count. y SHR AX,1

CY 0

SAR destination, count


y y y y y

Shifts each bit in the specified destination to the right. Copy of old MSB is put in the MSB position. LSB to carry flag. Number of shifts are indicated by count. SAR AX,1
CY

ROL destination, count


y Rotates each bit in the specified destination to the left. y MSB to new LSB & a new carry flag. y Number of shifts are indicated by count. y ROL AX,1

CY 0

ROR destination, count


y Rotates each bit in the specified destination to the right. y LSB to a new MSB & a new Carry. y Number of shifts are indicated by count. y ROR AX,1

CY

RCL destination, count


y Rotates each bit in the specified destination to the left along with

carry. y MSB to new carry & carry to new LSB. y Number of shifts are indicated by count. y RCL AX,CL
CY 0

RCR destination, count


y Rotates each bit in the specified destination to the right

along with carry flag. y LSB to a new carry & carry to a new MSB. y Number of shifts are indicated by count. y RCR AX,1
CY

STC: Sets the carry flag CLC: Resets the carry flag to zero CMC: Complements the carry flag

STD
y This is used to set the direction flag to one so that

SI/DI can be decremented automatically after execution of string instructions.

CLD
y This is used to reset the direction flag to zero so that

SI/DI can be incremented automatically after execution of string instructions.

STI:
y Sets the interrupt flag to one. yThis enables INTR interrupt of 8086.

CLI:
y Resets the interrupt flag to zero. y Due to this 8086 will not respond to an interrupt

signal on its INTR input.

Iteration control instructions


y Used to execute a series of instructions some number

of times. y The number is specified in CX. y CX is automatically decremented by one, each time after execute of LOOP instruction. y Until CX=0, execution will jump to a destination specified by a label in the instruction.

Instruction Code

Description

Condition for Exit

1. LOOP

Loop through a sequence of instructions Loop through a sequence of instructions Loop through a sequence of instructions

CX=0

2. LOOPE/LOOPZ

CX=0 or ZF=0

3. LOOPNE/LOOPNZ

CX=0 or ZF=1

Unconditional transfer instructions


y CALL y RET y JMP

CALL
y Used to transfer execution to a subprogram or

procedure. y Two types: near & far y A near CALL is a call to a procedure which is in the same code segment as the CALL instruction. y When 8086 executes a near CALL, it decrements the SP by 2 & copies the offset of the next instruction after the CALL on the stack. y IP is loaded with the offset of the first instruction of the procedure. y The near CALL is known as intra segment CALL.

CALL
y A far CALL is a call to a procedure which is in a

different segment from that which contains the CALL instruction. y When 8086 executes a far CALL, it decrements the SP by 2 & copies the contents of the CS register to the stack. y It then decrements the SP by 2 again & copies the offset of the next instruction after the CALL on the stack. y Finally, it loads CS with the segment base of the segment which contains the procedure & IP is loaded with the offset of the first instruction of the procedure. y The far CALL is known as inter segment CALL.

CALL
y CALL PRO y CALL DWORD PTR[BX]

RET
y It will return execution from a procedure to the next

instruction after the CALL instruction in the calling program.

JMP
y It will cause 8086 to fetch its next instruction from the

location specified in the instruction. y Two types: near & far. y A near JMP is a jump where destination location is in the same code segment. y A near JMP is known as intra segment JMP. y A far JMP is a jump where destination location is from different segment. y A far JMP is known as inter segment JMP. y JMP NEXT y JMP WORD PTR [BX]

J cond Conditional Transfer Instructions


y These instructions will cause a jump to a label given in

the instruction if the desired condition occurs in the program before execution of the instruction. y If the jump is not taken, execution simply goes on to the next instruction.

Interrupt Instructions

INT type
y Type refers to a number between 0

255 which

identifies the interrupt. y This instruction causes the 8086 to call a far procedure. y The address of the procedure is taken from the memory whose address is four times the type number.

INTO
y If the overflow flag is set, this instruction will cause

the 8086 to do an indirect far call to a procedure you write to handle overflow condition.

IRET
y It is used at the end of the interrupt service routine to

return execution to the interrupted program.

REP/REPE/REPZ/REPNE/REPNZ
y REP is a prefix which is written before one of the

string instructions y These instructions repeat until specified condition exists. y REPZ CMPSB ; compare string bytes until CX=0.
Instruction Code Condition for Exit

REP REPE/REPZ REPNE/REPNZ

CX=0 CX=0 OR ZF=0 CX=0 OR ZF=1

MOVS/MOVSB/MOVSW
y It copies a byte or word from a location in the data

segment to a location in the extra segment. y The offset of the source byte or word in the DS must be in the SI register. y The offset of the source byte or word in the ES must be in the DI register. y Count in CX register. y After byte or word is moved, SI & DI are automatically adjusted to point to the next source & destination. y If DF=0, then SI & DI are incremented; and if DF=1, SI & DI are decremented.

CMPS/CMPSB/CMPSW
y This instruction is used to compare a byte in one string

with a byte in another string. y SI is used to hold the offset of a byte or word in the source string & DI is used to hold the offset of a byte or word in the another string. y Comparison is done by subtracting the byte or word pointed to by DI from the byte or word pointed to by SI. y If both the byte or word strings are equal, zero flag is set. y AF,CF,OF,PF,SF,ZF are affected.

SCAS/SCASB/SCASW
y Compares a string byte with a byte in AL or a string

word with word in AX . y This instruction affects the flags. Neither operand is changed. y The string to be scanned must be in extra segment & DI must contain the offset of a byte or word to be compared . y After comparison DI will be automatically incremented or decremented according to DF to point to the next element in the two strings . y Whenever a match to the specified operand is found in the string, execution stops & ZF is set. y AF,CF,OF,PF,SF,ZF are affected.

LODS/LODSB/LODSW
y It copies a byte from a string location pointed to by SI

to AL, or a word from a string location pointed to by SI to AX. y It does not affect any flag.

STOS/STOSB/STOSW
y It copies a byte from AL or a word from AX to a

memory location in the extra segment. y DI is used to hold the offset of the memory location in ES. y After the copy DI will be automatically incremented or decremented according to DF to point to the next element in the memory . y It does not affect any flag.

External Hardware Synchronization Instructions

HLT
y It will cause the 8086 to stop fetching & executing

instructions. y The 8086 will enter a halt state. y The only ways to get the processor out of the halt state are with an interrupt signal on the INTR pin, an interrupt signal on the NMI pin, or a reset signal on the RESET input.

WAIT
y When this instruction executes, the 8086 enters an

idle condition where it is doing no processing. y The 8086 will stay in this idle state until a signal is asserted on the 8086 TEST input pin, or until a valid interrupt is received on the INTR or NMI pins. y If interrupt occurs while the 8086 is in this idle state, the 8086 will return to the idle state after the execution of the ISR. y WAIT is used to synchronize the 8086 with external hardware such as 8087.

ESC
y It is used to pass instructions to a coprocessor such as

8087, which shares the address & data bus with 8086. y Instructions for the coprocessor are represented by a 6-bit code embedded in the escape instruction. y In most cases, 8086 treats the ESC as NOP.

LOCK
y Multiprocessor system y LOCK prefix allows a microprocessor to make sure that

another processor does not take control of the system bus while it is in the middle of a critical instruction which uses the system bus.

NOP
y No Operation y Simply uses three clock cycles y Affects no flags y Used to increase delay of a loop y Can be used to hold a place in a program for an

instruction that will be added later.