8086 instruction set

Post on 29-Nov-2014

113 Views

Category:

Documents

5 Downloads

Preview:

Click to see full reader

TRANSCRIPT

MOV destination, sourceExamples:MOV BX,1234HMOV CL,[1000H]MOV AX,BX

PUSH sourceDecrements SP by 2 & copies a word from

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

PUSH CXPUSH DS

POP destinationCopies a word from stack to destinationSP is incremented by 2.Eg:

POP CXPOP DS

XCHG destination, sourceExamples:XCHG BX,CXXCHG AL,CL

XLAT : Translate byte in ALReplaces a byte in AL register with a byte

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

LEA : Load Effective AddressLEA register, sourceDetermines the offset of the source & loads

this address in the specified register.Eg:

LEA CX, TOTALLEA AX, [BX] [DI]

LDS, LES Loads DS/ES & the specified destination

register in the instruction with the contents of memory location specified as source in the instruction.

Eg: LDS BX, 5000H / LES BX,5000H

XX

YY

MM

NN

YY XX

NN MM

BX

DS/ES

5000

5001

5002

5003

LAHF: Load lower byte of flag register in AHCopies the contents of lower byte of 8086 flag

register to AH register.

SAHF: Copy AH register to lower byte of flag register

PUSHF : 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 portCopies data from a port to the accumulator.If 8-bit port is read, the data will go to AL.IN AL,F8HIN AX,95HIn indirect addressing, the address of the port

is referred from DX register.MOV DX,30F8HIN AL,DXIN AX,DX

OUT: Send a byte or word to portCopies data from a AL or AX to a port.OUT F8H,ALOUT FBH,AXIn indirect addressing, the address of the port

is referred from DX register.MOV DX,30F8HOUT DX, ALOUT DX, AX

CBW (Convert Byte to Word)Copies the sign of a byte in AL to all the bits

in AH.AH is said to be sign extension of AL.AX=0000 0000 1001 1000 = -152 decimalCBWAX=1111 1111 1001 1000 = -152 decimal

CWD (Convert Word to Double)Copies the sign of a word in AX to all the bits of

DX.DX is said to be sign extension of AX.DX=0000 0000 0000 0000AX=1111 0000 1100 0001 = -28865 decimalCWDDX=1111 1111 1111 1111AX=1111 0000 1100 0001 = -28865 decimal

DX:AX together can be used for 32-bit operand

ADD/ADC destination, sourceADD AL,30HADC DL,BLADD CX, [2048]

INC destinationAdds 1 to specified destination.INC BXINC CL

AAA: ASCII Adjust for AdditionThe numbers from 0-9 are represented as

30H-39H in ASCII code.For addition of two decimal numbers

represented in ASCII code, it is necessary to mask upper nibble(3) from code before addition.

8086 allows you to add ASCII codes for two decimals without masking off “3”.

AAA is used after addition to get the current result in unpacked BCD form.

AAA: ASCII Adjust for AdditionAL = 0011 0100 ASCII 4CL = 0011 1000 ASCII 8ADD AL,CL ; AL = 0110 1100AAA ; 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 AccumulatorThis instruction is used to make sure the

result of addition of two packed BCD numbers is adjusted to be a legal BCD number.

If the value of D3-D0 in the AL > 9 , or AF is set, the instruction adds 06 to D3-D0.

If the value of D7-D4 in the AL > 9 , or CF is set, the instruction adds 06 to D7-D4.

DAA : Decimal Adjust AccumulatorAL = 0011 1001 BCD 39CL = 0001 0010 BCD 12ADD AL,CL ; AL = 0100 1011 = 4BHDAA ; add 0110 because 1011 > 9 ; AL = 0101 0001 =51 BCD

The DAA works only on the AL register.

SUB/SBB destination, sourceSUB AL,30HSBB DL,BLSUB CX, [2046]

DEC destinationSubtracts 1 to specified destination.DEC BXDEC CL

NEG: Forms 2’s complementReplaces the number in a destination with

the 2’s compliment of that number.NEG AL

CMP destination, sourceCompares a byte/word from source with a

byte/word from destination.The source & the comparison is done by

subtracting source from destination. The result is not stored in destination.

Source & destination remain unchanged, only flags are updated.

CMP AL, 04HCMP CX,BX

AAS : ASCII Adjust after SubtractionThe numbers from 0-9 are represented as 30H-

39H in ASCII code.For subtraction of two decimal numbers

represented in ASCII code, it is necessary to mask upper nibble(3) from code before subtraction.

8086 allows you to subtract ASCII codes for two decimals without masking off “3”.

AAS is used after subtraction to get the current result in unpacked BCD form.

AAS : ASCII Adjust after SubtractionAL = 0011 0010 ASCII 2CL = 0011 1000 ASCII 8SUB AL,CL ; AL = 1111 1010 = FAH CF=1AAS ; AL =0000 0110 =BCD 6

; carry = 1 to indicate -6

DAS : Decimal Adjust After SubtractionThis instruction is used to make sure the

result of subtraction of two packed BCD numbers is adjusted to be a legal BCD number.

If the value of D3-D0 in the AL > 9 , or AF is set, the instruction subtracts 06 to D3-D0.

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 SubtractionAL = 0011 0010 BCD 32CL = 0001 0111 BCD 17SUB AL,CL ; AL = 0001 1011 = 1BHDAS ; subtract 0110 because 1011 > 9 ; AL = 0001 0101 =15 BCD

The DAS works only on the AL register.

MUL sourceUnsigned multiplicationWhen byte is multiplied by AL, the result is

stored in AX.When word is multiplied by AX, the MSW of

result is stored in DX & LSW of result is stored in AX.

MUL BLMUL BX

IMUL sourceSigned multiplicationWhen byte is multiplied by AL, the result is stored

in AX.When word is multiplied by AX, the MSW of result

is stored in DX & LSW of result is stored in AX.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.

IMUL BLIMUL BX

AAM: BCD adjust after multiplyAfter the two unpacked BCD digits are

multiplied, the AAM is used to adjust the product to unpacked BCD.

AL= 0000 0100 = unpacked BCD 4CL= 0000 0110 = unpacked BCD 6MUL CL ; AX=0000 0000 0001 1000 = 0018HAAM ; AX=0000 0010 0000 0100 = 0204

H

DIV sourceDivide unsigned word by byte or unsigned double

word by word.When dividing word by byte, word must be in AX.

After division AL=Quotient & AH= Remainder.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.

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.

DIV CLDIV CX

IDIV sourceDivide a signed word by a signed byte or a

signed double word by a signed word.

AAD: Binary Adjust before divisionConverts two unpacked BCD digits in AH & AL

to the equivalent binary number in AL.This adjustment must be made before

dividing the two unpacked BCD digits in AX by an unpacked BCD byte.

After division AL=unpacked BCD quotient, AH=unpacked BCD remainder.

AAD: Binary Adjust before divisionAX=0403 = unpacked BCD for 43 decimalCL=07HAAD ; adjust to binary before division

AX=002BHDIV CL ; AL=quotient= 06 unpacked BCD

; AH= remainder= 01 unpacked BCD

Bit Manipulation Instructions(Logical Instructions)

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

AND destination, sourceLogically ANDs each bit of the source byte or

word with the corresponding bit in the destination & stores result in the destination.

AL=1001 0011 =93HBL=0111 0101 = 75HAND BL,AL ; BL= 0001 0001 =11H

OR destination, sourceLogically ORs each bit of the source byte or

word with the corresponding bit in the destination & stores result in the destination.

AL=1001 0011 =93HBL=0111 0101 = 75HOR BL,AL ; BL= 1111 0111 =F7H

XOR destination, sourceLogically XORs each bit of the source byte or

word with the corresponding bit in the destination & stores result in the destination.

XOR BL,AL

TEST destination, sourceLogically ANDs contents of the source byte or

word with the contents of the destination.Neither operand is changed. Flags are

affected.PF, SF, ZF will be updated to show the result

of the ANDing.TEST AL,CLTEST AX,CX

SAL/SHL destination, countShifts each bit in the specified destination to the left & 0

is stored at LSB position.MSB to carry flag.Number of shifts are indicated by count.SAL AX,1

11101101

01110110

0

CY

1

0

SHR destination, countShifts each bit in the specified destination to the right &

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

11101101

11011010

0

CY

1

0

SAR destination, countShifts 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

11101101

11011011

CY

1

0

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

CY

11101101

11110110

0

1

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

11101101

11011011

CY

1

0

RCL destination, countRotates each bit in the specified destination to the left

along with carry.MSB to new carry & carry to new LSB.Number of shifts are indicated by count.RCL AX,CL

CY

11101101

01110110

0

1

RCR destination, countRotates each bit in the specified destination to the right

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

11101101

11011010

CY

1

0

STC: Sets the carry flag

CLC: Resets the carry flag to zero

CMC: Complements the carry flag

STDThis is used to set the direction flag to one so

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

CLDThis is used to reset the direction flag to zero

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

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

CLI:Resets the interrupt flag to zero.Due to this 8086 will not respond to an interrupt signal on its INTR input.

Iteration control instructionsUsed to execute a series of instructions some

number of times.The number is specified in CX.CX is automatically decremented by one,

each time after execute of LOOP instruction.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

CX=0

2. LOOPE/LOOPZ Loop through a sequence of instructions

CX=0 or ZF=0

3. LOOPNE/LOOPNZ Loop through a sequence of instructions

CX=0 or ZF=1

Unconditional transfer instructionsCALLRETJMP

CALLUsed to transfer execution to a subprogram or

procedure.Two types: near & farA near CALL is a call to a procedure which is in

the same code segment as the CALL instruction.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.

IP is loaded with the offset of the first instruction of the procedure.

The near CALL is known as intra segment CALL.

CALLA far CALL is a call to a procedure which is in

a different segment from that which contains the CALL instruction.

When 8086 executes a far CALL, it decrements the SP by 2 & copies the contents of the CS register to the stack.

It then decrements the SP by 2 again & copies the offset of the next instruction after the CALL on the stack.

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.

The far CALL is known as inter segment CALL.

CALLCALL PROCALL DWORD PTR[BX]

RETIt will return execution from a procedure to

the next instruction after the CALL instruction in the calling program.

JMPIt will cause 8086 to fetch its next instruction

from the location specified in the instruction.Two types: near & far.A near JMP is a jump where destination

location is in the same code segment.A near JMP is known as intra segment JMP.A far JMP is a jump where destination

location is from different segment.A far JMP is known as inter segment JMP.JMP NEXTJMP WORD PTR [BX]

J cond – Conditional Transfer InstructionsThese 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.

If the jump is not taken, execution simply goes on to the next instruction.

Interrupt InstructionsInterrupt Instructions

INT typeType refers to a number between 0 – 255

which identifies the interrupt.This instruction causes the 8086 to call a far

procedure.The address of the procedure is taken from

the memory whose address is four times the type number.

INTOIf 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.

IRETIt is used at the end of the interrupt service

routine to return execution to the interrupted program.

REP/REPE/REPZ/REPNE/REPNZREP is a prefix which is written before one of

the string instructionsThese instructions repeat until specified

condition exists.REPZ CMPSB ; compare string bytes until

CX=0.Instruction Code Condition for Exit

REP CX=0

REPE/REPZ CX=0 OR ZF=0

REPNE/REPNZ CX=0 OR ZF=1

MOVS/MOVSB/MOVSWIt copies a byte or word from a location in the data segment

to a location in the extra segment.The offset of the source byte or word in the DS must be in the

SI register.The offset of the source byte or word in the ES must be in the

DI register.Count in CX register.After byte or word is moved, SI & DI are automatically

adjusted to point to the next source & destination.If DF=0, then SI & DI are incremented; and if DF=1, SI & DI are

decremented.

CMPS/CMPSB/CMPSWThis instruction is used to compare a byte in one

string with a byte in another string.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.

Comparison is done by subtracting the byte or word pointed to by DI from the byte or word pointed to by SI.

If both the byte or word strings are equal, zero flag is set.

AF,CF,OF,PF,SF,ZF are affected.

SCAS/SCASB/SCASWCompares a string byte with a byte in AL or a

string word with word in AX .This instruction affects the flags. Neither

operand is changed.The string to be scanned must be in extra

segment & DI must contain the offset of a byte or word to be compared .

After comparison DI will be automatically incremented or decremented according to DF to point to the next element in the two strings .

Whenever a match to the specified operand is found in the string, execution stops & ZF is set.

AF,CF,OF,PF,SF,ZF are affected.

LODS/LODSB/LODSWIt 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.

It does not affect any flag.

STOS/STOSB/STOSWIt copies a byte from AL or a word from AX to

a memory location in the extra segment.DI is used to hold the offset of the memory

location in ES.After the copy DI will be automatically

incremented or decremented according to DF to point to the next element in the memory .

It does not affect any flag.

External Hardware Synchronization Instructions

HLTIt will cause the 8086 to stop fetching &

executing instructions.The 8086 will enter a halt state.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.

WAITWhen this instruction executes, the 8086 enters

an idle condition where it is doing no processing.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.

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.

WAIT is used to synchronize the 8086 with external hardware such as 8087.

ESCIt is used to pass instructions to a

coprocessor such as 8087, which shares the address & data bus with 8086.

Instructions for the coprocessor are represented by a 6-bit code embedded in the escape instruction.

In most cases, 8086 treats the ESC as NOP.

LOCKMultiprocessor systemLOCK 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.

NOPNo OperationSimply uses three clock cyclesAffects no flagsUsed to increase delay of a loopCan be used to hold a place in a program for

an instruction that will be added later.

top related