Sie sind auf Seite 1von 48

Complete8086instructionset

Quickreference:
AAA
AAD
AAM
AAS
ADC
ADD
AND
CALL
CBW
CLC
CLD
CLI
CMC
CMP

CMPSB
CMPSW
CWD
DAA
DAS
DEC
DIV
HLT
IDIV
IMUL
IN
INC
INT
INTO
IRET
JA

JAE
JB
JBE
JC
JCXZ
JE
JG
JGE
JL
JLE
JMP
JNA
JNAE
JNB

JNBE
JNC
JNE
JNG
JNGE
JNL
JNLE
JNO
JNP
JNS
JNZ
JO
JP
JPE

JPO
JS
JZ
LAHF
LDS
LEA
LES
LODSB
LODSW
LOOP
LOOPE
LOOPNE
LOOPNZ
LOOPZ

MOV
MOVSB
MOVSW
MUL
NEG
NOP
NOT
OR
OUT
POP
POPA
POPF
PUSH
PUSHA
PUSHF
RCL

RCR
REP
REPE
REPNE
REPNZ
REPZ
RET
RETF
ROL
ROR
SAHF
SAL
SAR
SBB

SCASB
SCASW
SHL
SHR
STC
STD
STI
STOSB
STOSW
SUB
TEST
XCHG
XLATB
XOR

Copyright20032005Emu8086,Inc.
Allrightsreserved.
http://www.emu8086.com

Operandtypes:
REG:AX,BX,CX,DX,AH,AL,BL,BH,CH,CL,DH,DL,DI,SI,BP,SP.
SREG:DS,ES,SS,andonlyassecondoperand:CS.
memory:[BX],[BX+SI+7],variable,etc...
immediate:5,24,3Fh,10001101b,etc...

Notes:
Whentwooperandsarerequiredforaninstructiontheyareseparatedbycomma.For
example:
REG,memory
Whentherearetwooperands,bothoperandsmusthavethesamesize(exceptshift
androtateinstructions).Forexample:

AL,DL
DX,AX
m1DB?
AL,m1
m2DW?
AX,m2
Someinstructionsallowseveraloperandcombinations.Forexample:
memory,immediate
REG,immediate
memory,REG
REG,SREG

Instructionsinalphabeticalorder:

Instruction

Operands

Description
ASCIIAdjustafterAddition.
CorrectsresultinAHandALafteraddition
whenworkingwithBCDvalues.
Itworksaccordingtothefollowing
Algorithm:

AAA

Nooperands

iflownibbleofAL>9orAF=1then:
AL=AL+6
AH=AH+1
AF=1
CF=1
else
AF=0
CF=0
inbothcases:
clearthehighnibbleofAL.
Example:
MOVAX,15AH=00,AL=0Fh
AAAAH=01,AL=05
RET
C ZSO PA
r ? ? ? ? r

ASCIIAdjustbeforeDivision.

PreparestwoBCDvaluesfordivision.
Algorithm:
AL=(AH*10)+AL
AH=0
AAD

Nooperands

Example:
MOVAX,0105hAH=01,AL=05
AADAH=00,AL=0Fh(15)
RET
C ZSO PA
? r r ? r ?

ASCIIAdjustafterMultiplication.
Correctstheresultofmultiplicationoftwo
BCDvalues.
Algorithm:
AH=AL/10
AL=remainder

AAM

Nooperands

Example:
MOVAL,15AL=0Fh
AAMAH=01,AL=05
RET
C ZSO PA
? r r ? r ?

ASCIIAdjustafterSubtraction.
CorrectsresultinAHandALafter
subtractionwhenworkingwithBCDvalues.
Algorithm:

AAS

Nooperands

iflownibbleofAL>9orAF=1then:
AL=AL6
AH=AH1
AF=1
CF=1
else
AF=0
CF=0
inbothcases:
clearthehighnibbleofAL.

Example:
MOVAX,02FFhAH=02,AL=0FFh
AASAH=01,AL=09
RET
C ZSO PA
r ? ? ? ? r

AddwithCarry.
Algorithm:
operand1=operand1+operand2+CF
ADC

REG,memory
memory,REG
REG,REG
memory,immediate
REG,immediate

Example:
STCsetCF=1
MOVAL,5AL=5
ADCAL,1AL=7
RET
C ZSO PA
r r r r r r

Add.
Algorithm:

ADD

REG,memory
memory,REG
REG,REG
memory,immediate
REG,immediate

operand1=operand1+operand2
Example:
MOVAL,5AL=5
ADDAL,3AL=2
RET
C ZSO PA
r r r r r r

LogicalANDbetweenallbitsoftwo
operands.Resultisstoredinoperand1.
Theserulesapply:
1AND1=1
1AND0=0

AND

REG,memory
memory,REG
REG,REG
memory,immediate
REG,immediate

0AND1=0
0AND0=0
Example:
MOVAL,'a'AL=01100001b
ANDAL,11011111bAL=01000001b('A')
RET
C ZSO P
0 r r 0 r

Transferscontroltoprocedure,return
addressis(IP)ispushedtostack.4byte
addressmaybeenteredinthisform:
1234h:5678h,firstvalueisasegmentsecond
valueisanoffset(thisisafarcall,soCSis
alsopushedtostack).
Example:
#make_COM#
ORG100hforCOMfile.

CALL

procedurename
label
4byteaddress

CALLp1
ADDAX,1
RETreturntoOS.
p1PROCproceduredeclaration.
MOVAX,1234h
RETreturntocaller.
p1ENDP
C ZSO PA
unchanged

Convertbyteintoword.
Algorithm:
ifhighbitofAL=1then:
AH=255(0FFh)
else
AH=0

CBW

Nooperands

Example:

MOVAX,0AH=0,AL=0
MOVAL,5AX=000FBh(251)
CBWAX=0FFFBh(5)
RET
C ZSO PA
unchanged

ClearCarryflag.
Algorithm:
CLC

Nooperands

CF=0
C
0

ClearDirectionflag.SIandDIwillbe
incrementedbychaininstructions:CMPSB,
CMPSW,LODSB,LODSW,MOVSB,
MOVSW,STOSB,STOSW.

CLD

Nooperands

Algorithm:
DF=0
D
0

ClearInterruptenableflag.Thisdisables
hardwareinterrupts.
Algorithm:

CLI

Nooperands

IF=0
I
0

ComplementCarryflag.InvertsvalueofCF.
Algorithm:
ifCF=1thenCF=0
ifCF=0thenCF=1

CMC

Nooperands
C
r

Compare.
Algorithm:
operand1operand2

CMP

REG,memory
memory,REG
REG,REG
memory,immediate
REG,immediate

resultisnotstoredanywhere,flagsareset(OF,
SF,ZF,AF,PF,CF)accordingtoresult.
Example:
MOVAL,5
MOVBL,5
CMPAL,BLAL=5,ZF=1(soequal!)
RET
C ZSO PA
r r r r r r

Comparebytes:ES:[DI]fromDS:[SI].
Algorithm:

CMPSB

DS:[SI]ES:[DI]
setflagsaccordingtoresult:
OF,SF,ZF,AF,PF,CF
ifDF=0then
SI=SI+1
DI=DI+1
else
SI=SI1
DI=DI1

Nooperands

C ZSO PA
r r r r r r

Comparewords:ES:[DI]fromDS:[SI].
Algorithm:
DS:[SI]ES:[DI]

CMPSW

setflagsaccordingtoresult:
OF,SF,ZF,AF,PF,CF
ifDF=0then
SI=SI+2
DI=DI+2
else
SI=SI2
DI=DI2

Nooperands

C ZSO PA
r r r r r r

ConvertWordtoDoubleword.
Algorithm:
ifhighbitofAX=1then:
DX=65535(0FFFFh)
else
DX=0
CWD

Nooperands

Example:
MOVDX,0DX=0
MOVAX,0AX=0
MOVAX,5DXAX=00000h:0FFFBh
CWDDXAX=0FFFFh:0FFFBh
RET
C ZSO PA
unchanged

DecimaladjustAfterAddition.
Correctstheresultofadditionoftwopacked
BCDvalues.
Algorithm:

DAA

Nooperands

iflownibbleofAL>9orAF=1then:
AL=AL+6
AF=1
ifAL>9FhorCF=1then:
AL=AL+60h
CF=1
Example:
MOVAL,0FhAL=0Fh(15)

DAAAL=15h
RET
C ZSO PA
r r r r r r

DecimaladjustAfterSubtraction.
Correctstheresultofsubtractionoftwo
packedBCDvalues.
Algorithm:

DAS

Nooperands

iflownibbleofAL>9orAF=1then:
AL=AL6
AF=1
ifAL>9FhorCF=1then:
AL=AL60h
CF=1
Example:
MOVAL,0FFhAL=0FFh(1)
DASAL=99h,CF=1
RET
C ZSO PA
r r r r r r

Decrement.
Algorithm:
operand=operand1

DEC

REG
memory

Example:
MOVAL,255AL=0FFh(255or1)
DECALAL=0FEh(254or2)
RET
ZSO PA
r r r r r
CFunchanged!
Unsigneddivide.
Algorithm:

whenoperandisabyte:
AL=AX/operand
AH=remainder(modulus)

DIV

whenoperandisaword:
AX=(DXAX)/operand
DX=remainder(modulus)

REG
memory

Example:
MOVAX,203AX=00CBh
MOVBL,4
DIVBLAL=50(32h),AH=3
RET
C ZSO PA
? ? ? ? ? ?

HalttheSystem.
Example:
HLT

Nooperands

MOVAX,5
HLT
C ZSO PA
unchanged

Signeddivide.
Algorithm:
whenoperandisabyte:
AL=AX/operand
AH=remainder(modulus)

IDIV

whenoperandisaword:
AX=(DXAX)/operand
DX=remainder(modulus)

REG
memory

Example:
MOVAX,203AX=0FF35h
MOVBL,4
IDIVBLAL=50(0CEh),AH=3(0FDh)
RET
C ZSO PA
? ? ? ? ? ?

Signedmultiply.
Algorithm:
whenoperandisabyte:
AX=AL*operand.
whenoperandisaword:
(DXAX)=AX*operand.
IMUL

REG
memory

Example:
MOVAL,2
MOVBL,4
IMULBLAX=8
RET
C ZSO PA
r ? ? r ? ?
CF=OF=0whenresultfitsintooperandof
IMUL.

IN

AL,im.byte
AL,DX
AX,im.byte
AX,DX

InputfromportintoALorAX.
Secondoperandisaportnumber.If
requiredtoaccessportnumberover255
DXregistershouldbeused.
Example:
INAX,4getstatusoftrafficlights.
INAL,7getstatusofsteppermotor.
C ZSO PA
unchanged

Increment.
Algorithm:
operand=operand+1

INC

REG
memory

Example:
MOVAL,4
INCALAL=5
RET
ZSO PA
r r r r r
CFunchanged!

Interruptnumberedbyimmediatebyte
(0..255).
Algorithm:
INT

immediatebyte

Pushtostack:
flagsregister
CS
IP

IF=0
Transfercontrolto
interruptprocedure
Example:
MOVAH,0Ehteletype.
MOVAL,'A'
INT10hBIOSinterrupt.
RET
C ZSO PAI
unchanged
0
INTONooperandsInterrupt4ifOverflowflagis1.
Algorithm:
ifOF=1thenINT4
Example:
5127=132(notin128..127)
theresultofSUBiswrong(124),
soOF=1isset:
MOVAL,5
SUBAL,127AL=7Ch(124)
INTOprocesserror.
RET
IRETNooperandsInterruptReturn.
Algorithm:
Popfromstack:
IP
CS
flagsregister
C ZSO PA
popped
JAlabelShortJumpiffirstoperandisAbovesecondoperand(assetbyCMPinstruction).

Unsigned.
Algorithm:
if(CF=0)and(ZF=0)thenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,250
CMPAL,5
JAlabel1
PRINT'ALisnotabove5'
JMPexit
label1:
PRINT'ALisabove5'
exit:
RET
C ZSO PA
unchanged
JAElabelShortJumpiffirstoperandisAboveorEqualtosecondoperand(assetbyCMP
instruction).Unsigned.
Algorithm:
ifCF=0thenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,5
CMPAL,5
JAElabel1
PRINT'ALisnotaboveorequalto5'
JMPexit
label1:
PRINT'ALisaboveorequalto5'
exit:
RET
C ZSO PA
unchanged
JBlabelShortJumpiffirstoperandisBelowsecondoperand(assetbyCMPinstruction).
Unsigned.
Algorithm:
ifCF=1thenjump
Example:
include'emu8086.inc'

#make_COM#
ORG100h
MOVAL,1
CMPAL,5
JBlabel1
PRINT'ALisnotbelow5'
JMPexit
label1:
PRINT'ALisbelow5'
exit:
RET
C ZSO PA
unchanged
JBElabelShortJumpiffirstoperandisBeloworEqualtosecondoperand(assetbyCMP
instruction).Unsigned.
Algorithm:
ifCF=1orZF=1thenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,5
CMPAL,5
JBElabel1
PRINT'ALisnotbeloworequalto5'
JMPexit
label1:
PRINT'ALisbeloworequalto5'
exit:
RET
C ZSO PA
unchanged
JClabelShortJumpifCarryflagissetto1.
Algorithm:
ifCF=1thenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,255
ADDAL,1
JClabel1
PRINT'nocarry.'
JMPexit
label1:

PRINT'hascarry.'
exit:
RET
C ZSO PA
unchanged
JCXZlabelShortJumpifCXregisteris0.
Algorithm:
ifCX=0thenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVCX,0
JCXZlabel1
PRINT'CXisnotzero.'
JMPexit
label1:
PRINT'CXiszero.'
exit:
RET
C ZSO PA
unchanged
JElabelShortJumpiffirstoperandisEqualtosecondoperand(assetbyCMPinstruction).
Signed/Unsigned.
Algorithm:
ifZF=1thenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,5
CMPAL,5
JElabel1
PRINT'ALisnotequalto5.'
JMPexit
label1:
PRINT'ALisequalto5.'
exit:
RET
C ZSO PA
unchanged
JGlabelShortJumpiffirstoperandisGreaterthensecondoperand(assetbyCMP
instruction).Signed.

Algorithm:
if(ZF=0)and(SF=OF)thenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,5
CMPAL,5
JGlabel1
PRINT'ALisnotgreater5.'
JMPexit
label1:
PRINT'ALisgreater5.'
exit:
RET
C ZSO PA
unchanged
JGElabelShortJumpiffirstoperandisGreaterorEqualtosecondoperand(assetbyCMP
instruction).Signed.
Algorithm:
ifSF=OFthenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,2
CMPAL,5
JGElabel1
PRINT'AL<5'
JMPexit
label1:
PRINT'AL>=5'
exit:
RET
C ZSO PA
unchanged
JLlabelShortJumpiffirstoperandisLessthensecondoperand(assetbyCMP
instruction).Signed.
Algorithm:
ifSF<>OFthenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h

MOVAL,2
CMPAL,5
JLlabel1
PRINT'AL>=5.'
JMPexit
label1:
PRINT'AL<5.'
exit:
RET
C ZSO PA
unchanged
JLElabelShortJumpiffirstoperandisLessorEqualtosecondoperand(assetbyCMP
instruction).Signed.
Algorithm:
ifSF<>OForZF=1thenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,2
CMPAL,5
JLElabel1
PRINT'AL>5.'
JMPexit
label1:
PRINT'AL<=5.'
exit:
RET
C ZSO PA
unchanged
JMPlabel
4byteaddress
UnconditionalJump.Transferscontroltoanotherpartoftheprogram.4byteaddressmay
beenteredinthisform:1234h:5678h,firstvalueisasegmentsecondvalueisanoffset.
Algorithm:
alwaysjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,5
JMPlabel1jumpover2lines!
PRINT'NotJumped!'
MOVAL,0

label1:
PRINT'GotHere!'
RET
C ZSO PA
unchanged
JNAlabelShortJumpiffirstoperandisNotAbovesecondoperand(assetbyCMP
instruction).Unsigned.
Algorithm:
ifCF=1orZF=1thenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,2
CMPAL,5
JNAlabel1
PRINT'ALisabove5.'
JMPexit
label1:
PRINT'ALisnotabove5.'
exit:
RET
C ZSO PA
unchanged
JNAElabelShortJumpiffirstoperandisNotAboveandNotEqualtosecondoperand(as
setbyCMPinstruction).Unsigned.
Algorithm:
ifCF=1thenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,2
CMPAL,5
JNAElabel1
PRINT'AL>=5.'
JMPexit
label1:
PRINT'AL<5.'
exit:
RET
C ZSO PA
unchanged
JNBlabelShortJumpiffirstoperandisNotBelowsecondoperand(assetbyCMP

instruction).Unsigned.
Algorithm:
ifCF=0thenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,7
CMPAL,5
JNBlabel1
PRINT'AL<5.'
JMPexit
label1:
PRINT'AL>=5.'
exit:
RET
C ZSO PA
unchanged
JNBElabelShortJumpiffirstoperandisNotBelowandNotEqualtosecondoperand(as
setbyCMPinstruction).Unsigned.
Algorithm:
if(CF=0)and(ZF=0)thenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,7
CMPAL,5
JNBElabel1
PRINT'AL<=5.'
JMPexit
label1:
PRINT'AL>5.'
exit:
RET
C ZSO PA
unchanged
JNClabelShortJumpifCarryflagissetto0.
Algorithm:
ifCF=0thenjump
Example:
include'emu8086.inc'
#make_COM#

ORG100h
MOVAL,2
ADDAL,3
JNClabel1
PRINT'hascarry.'
JMPexit
label1:
PRINT'nocarry.'
exit:
RET
C ZSO PA
unchanged
JNElabelShortJumpiffirstoperandisNotEqualtosecondoperand(assetbyCMP
instruction).Signed/Unsigned.
Algorithm:
ifZF=0thenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,2
CMPAL,3
JNElabel1
PRINT'AL=3.'
JMPexit
label1:
PRINT'Al<>3.'
exit:
RET
C ZSO PA
unchanged
JNGlabelShortJumpiffirstoperandisNotGreaterthensecondoperand(assetbyCMP
instruction).Signed.
Algorithm:
if(ZF=1)and(SF<>OF)thenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,2
CMPAL,3
JNGlabel1
PRINT'AL>3.'
JMPexit
label1:

PRINT'Al<=3.'
exit:
RET
C ZSO PA
unchanged
JNGElabelShortJumpiffirstoperandisNotGreaterandNotEqualtosecondoperand(as
setbyCMPinstruction).Signed.
Algorithm:
ifSF<>OFthenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,2
CMPAL,3
JNGElabel1
PRINT'AL>=3.'
JMPexit
label1:
PRINT'Al<3.'
exit:
RET
C ZSO PA
unchanged
JNLlabelShortJumpiffirstoperandisNotLessthensecondoperand(assetbyCMP
instruction).Signed.
Algorithm:
ifSF=OFthenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,2
CMPAL,3
JNLlabel1
PRINT'AL<3.'
JMPexit
label1:
PRINT'Al>=3.'
exit:
RET
C ZSO PA
unchanged
JNLElabelShortJumpiffirstoperandisNotLessandNotEqualtosecondoperand(asset

byCMPinstruction).Signed.
Algorithm:
if(SF=OF)and(ZF=0)thenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,2
CMPAL,3
JNLElabel1
PRINT'AL<=3.'
JMPexit
label1:
PRINT'Al>3.'
exit:
RET
C ZSO PA
unchanged
JNOlabelShortJumpifNotOverflow.
Algorithm:
ifOF=0thenjump
Example:
52=7(inside128..127)
theresultofSUBiscorrect,
soOF=0:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,5
SUBAL,2AL=0F9h(7)
JNOlabel1
PRINT'overflow!'
JMPexit
label1:
PRINT'nooverflow.'
exit:
RET
C ZSO PA
unchanged
JNPlabelShortJumpifNoParity(odd).Only8lowbitsofresultarechecked.SetbyCMP,
SUB,ADD,TEST,AND,OR,XORinstructions.
Algorithm:

ifPF=0thenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,00000111bAL=7
ORAL,0justsetflags.
JNPlabel1
PRINT'parityeven.'
JMPexit
label1:
PRINT'parityodd.'
exit:
RET
C ZSO PA
unchanged
JNSlabelShortJumpifNotSigned(ifpositive).SetbyCMP,SUB,ADD,TEST,AND,OR,
XORinstructions.
Algorithm:
ifSF=0thenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,00000111bAL=7
ORAL,0justsetflags.
JNSlabel1
PRINT'signed.'
JMPexit
label1:
PRINT'notsigned.'
exit:
RET
C ZSO PA
unchanged
JNZlabelShortJumpifNotZero(notequal).SetbyCMP,SUB,ADD,TEST,AND,OR,
XORinstructions.
Algorithm:
ifZF=0thenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,00000111bAL=7
ORAL,0justsetflags.

JNZlabel1
PRINT'zero.'
JMPexit
label1:
PRINT'notzero.'
exit:
RET
C ZSO PA
unchanged
JOlabelShortJumpifOverflow.
Algorithm:
ifOF=1thenjump
Example:
5127=132(notin128..127)
theresultofSUBiswrong(124),
soOF=1isset:
include'emu8086.inc'
#make_COM#
org100h
MOVAL,5
SUBAL,127AL=7Ch(124)
JOlabel1
PRINT'nooverflow.'
JMPexit
label1:
PRINT'overflow!'
exit:
RET
C ZSO PA
unchanged
JPlabelShortJumpifParity(even).Only8lowbitsofresultarechecked.SetbyCMP,
SUB,ADD,TEST,AND,OR,XORinstructions.
Algorithm:
ifPF=1thenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,00000101bAL=5
ORAL,0justsetflags.
JPlabel1
PRINT'parityodd.'
JMPexit
label1:

PRINT'parityeven.'
exit:
RET
C ZSO PA
unchanged
JPElabelShortJumpifParityEven.Only8lowbitsofresultarechecked.SetbyCMP,
SUB,ADD,TEST,AND,OR,XORinstructions.
Algorithm:
ifPF=1thenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,00000101bAL=5
ORAL,0justsetflags.
JPElabel1
PRINT'parityodd.'
JMPexit
label1:
PRINT'parityeven.'
exit:
RET
C ZSO PA
unchanged
JPOlabelShortJumpifParityOdd.Only8lowbitsofresultarechecked.SetbyCMP,SUB,
ADD,TEST,AND,OR,XORinstructions.
Algorithm:
ifPF=0thenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,00000111bAL=7
ORAL,0justsetflags.
JPOlabel1
PRINT'parityeven.'
JMPexit
label1:
PRINT'parityodd.'
exit:
RET
C ZSO PA
unchanged
JSlabelShortJumpifSigned(ifnegative).SetbyCMP,SUB,ADD,TEST,AND,OR,XOR

instructions.
Algorithm:
ifSF=1thenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,10000000bAL=128
ORAL,0justsetflags.
JSlabel1
PRINT'notsigned.'
JMPexit
label1:
PRINT'signed.'
exit:
RET
C ZSO PA
unchanged
JZlabelShortJumpifZero(equal).SetbyCMP,SUB,ADD,TEST,AND,OR,XOR
instructions.
Algorithm:
ifZF=1thenjump
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVAL,5
CMPAL,5
JZlabel1
PRINT'ALisnotequalto5.'
JMPexit
label1:
PRINT'ALisequalto5.'
exit:
RET
C ZSO PA
unchanged
LAHFNooperandsLoadAHfrom8lowbitsofFlagsregister.
Algorithm:
AH=flagsregister
AHbit:76543210
[SF][ZF][0][AF][0][PF][1][CF]

bits1,3,5arereserved.
C ZSO PA
unchanged
LDSREG,memoryLoadmemorydoublewordintowordregisterandDS.
Algorithm:
REG=firstword
DS=secondword
Example:
#make_COM#
ORG100h
LDSAX,m
RET
mDW1234h
DW5678h
END
AXissetto1234h,DSissetto5678h.
C ZSO PA
unchanged
LEAREG,memoryLoadEffectiveAddress.
Algorithm:
REG=addressofmemory(offset)
GenerallythisinstructionisreplacedbyMOVwhenassemblingwhenpossible.
Example:
#make_COM#
ORG100h
LEAAX,m
RET
mDW1234h
END

AXissetto:0104h.
LEAinstructiontakes3bytes,RETtakes1byte,westartat100h,sotheaddressof'm'is
104h.
C ZSO PA
unchanged
LESREG,memoryLoadmemorydoublewordintowordregisterandES.
Algorithm:
REG=firstword
ES=secondword
Example:
#make_COM#
ORG100h
LESAX,m
RET
mDW1234h
DW5678h
END
AXissetto1234h,ESissetto5678h.
C ZSO PA
unchanged
LODSBNooperandsLoadbyteatDS:[SI]intoAL.UpdateSI.
Algorithm:
AL=DS:[SI]
ifDF=0then
SI=SI+1
else
SI=SI1
Example:
#make_COM#
ORG100h
LEASI,a1
MOVCX,5
MOVAH,0Eh
m:LODSB
INT10h

LOOPm
RET
a1DB'H','e','l','l','o'
C ZSO PA
unchanged
LODSWNooperandsLoadwordatDS:[SI]intoAX.UpdateSI.
Algorithm:
AX=DS:[SI]
ifDF=0then
SI=SI+2
else
SI=SI2
Example:
#make_COM#
ORG100h
LEASI,a1
MOVCX,5
REPLODSWfinallytherewillbe555hinAX.
RET
a1dw111h,222h,333h,444h,555h
C ZSO PA
unchanged
LOOPlabelDecreaseCX,jumptolabelifCXnotzero.
Algorithm:
CX=CX1
ifCX<>0then
jump
else
nojump,continue
Example:
include'emu8086.inc'
#make_COM#
ORG100h
MOVCX,5
label1:
PRINTN'loop!'
LOOPlabel1
RET

C ZSO PA
unchanged
LOOPElabelDecreaseCX,jumptolabelifCXnotzeroandEqual(ZF=1).
Algorithm:
CX=CX1
if(CX<>0)and(ZF=1)then
jump
else
nojump,continue
Example:
LoopuntilresultfitsintoALalone,
or5times.Theresultwillbeover255
onthirdloop(100+100+100),
soloopwillexit.
include'emu8086.inc'
#make_COM#
ORG100h
MOVAX,0
MOVCX,5
label1:
PUTC'*'
ADDAX,100
CMPAH,0
LOOPElabel1
RET
C ZSO PA
unchanged
LOOPNElabelDecreaseCX,jumptolabelifCXnotzeroandNotEqual(ZF=0).
Algorithm:
CX=CX1
if(CX<>0)and(ZF=0)then
jump
else
nojump,continue
Example:
Loopuntil'7'isfound,
or5times.
include'emu8086.inc'
#make_COM#
ORG100h
MOVSI,0
MOVCX,5
label1:
PUTC'*'

MOVAL,v1[SI]
INCSInextbyte(SI=SI+1).
CMPAL,7
LOOPNElabel1
RET
v1db9,8,7,6,5
C ZSO PA
unchanged
LOOPNZlabelDecreaseCX,jumptolabelifCXnotzeroandZF=0.
Algorithm:
CX=CX1
if(CX<>0)and(ZF=0)then
jump
else
nojump,continue
Example:
Loopuntil'7'isfound,
or5times.
include'emu8086.inc'
#make_COM#
ORG100h
MOVSI,0
MOVCX,5
label1:
PUTC'*'
MOVAL,v1[SI]
INCSInextbyte(SI=SI+1).
CMPAL,7
LOOPNZlabel1
RET
v1db9,8,7,6,5
C ZSO PA
unchanged
LOOPZlabelDecreaseCX,jumptolabelifCXnotzeroandZF=1.
Algorithm:
CX=CX1
if(CX<>0)and(ZF=1)then
jump
else
nojump,continue
Example:
LoopuntilresultfitsintoALalone,
or5times.Theresultwillbeover255
onthirdloop(100+100+100),

soloopwillexit.
include'emu8086.inc'
#make_COM#
ORG100h
MOVAX,0
MOVCX,5
label1:
PUTC'*'
ADDAX,100
CMPAH,0
LOOPZlabel1
RET
C ZSO PA
unchanged
MOVREG,memory
memory,REG
REG,REG
memory,immediate
REG,immediate
SREG,memory
memory,SREG
REG,SREG
SREG,REGCopyoperand2tooperand1.
TheMOVinstructioncannot:
setthevalueoftheCSandIPregisters.
copyvalueofonesegmentregistertoanothersegmentregister(shouldcopyto
generalregisterfirst).
copyimmediatevaluetosegmentregister(shouldcopytogeneralregisterfirst).
Algorithm:
operand1=operand2
Example:
#make_COM#
ORG100h
MOVAX,0B800hsetAX=B800h(VGAmemory).
MOVDS,AXcopyvalueofAXtoDS.
MOVCL,'A'CL=41h(ASCIIcode).
MOVCH,01011111bCL=colorattribute.
MOVBX,15EhBX=positiononscreen.
MOV[BX],CXw.[0B800h:015Eh]=CX.
RETreturnstooperatingsystem.
C ZSO PA
unchanged
MOVSBNooperandsCopybyteatDS:[SI]toES:[DI].UpdateSIandDI.

Algorithm:
ES:[DI]=DS:[SI]
ifDF=0then
SI=SI+1
DI=DI+1
else
SI=SI1
DI=DI1
Example:
#make_COM#
ORG100h
LEASI,a1
LEADI,a2
MOVCX,5
REPMOVSB
RET
a1DB1,2,3,4,5
a2DB5DUP(0)
C ZSO PA
unchanged
MOVSWNooperandsCopywordatDS:[SI]toES:[DI].UpdateSIandDI.
Algorithm:
ES:[DI]=DS:[SI]
ifDF=0then
SI=SI+2
DI=DI+2
else
SI=SI2
DI=DI2
Example:
#make_COM#
ORG100h
LEASI,a1
LEADI,a2
MOVCX,5
REPMOVSW
RET
a1DW1,2,3,4,5
a2DW5DUP(0)
C ZSO PA

unchanged
MULREG
memory
Unsignedmultiply.
Algorithm:
whenoperandisabyte:
AX=AL*operand.
whenoperandisaword:
(DXAX)=AX*operand.
Example:
MOVAL,200AL=0C8h
MOVBL,4
MULBLAX=0320h(800)
RET
C ZSO PA
r ? ? r ? ?
CF=OF=0whenhighsectionoftheresultiszero.NEGREG
memory
Negate.Makesoperandnegative(two'scomplement).
Algorithm:
Invertallbitsoftheoperand
Add1toinvertedoperand
Example:
MOVAL,5AL=05h
NEGALAL=0FBh(5)
NEGALAL=05h(5)
RET
C ZSO PA
r r r r r r
NOPNooperandsNoOperation.
Algorithm:
Donothing
Example:
donothing,3times:
NOP
NOP
NOP
RET
C ZSO PA

unchanged
NOTREG
memory
Inverteachbitoftheoperand.
Algorithm:
ifbitis1turnitto0.
ifbitis0turnitto1.
Example:
MOVAL,00011011b
NOTALAL=11100100b
RET
C ZSO PA
unchanged
ORREG,memory
memory,REG
REG,REG
memory,immediate
REG,immediateLogicalORbetweenallbitsoftwooperands.Resultisstoredinfirst
operand.
Theserulesapply:
1OR1=1
1OR0=1
0OR1=1
0OR0=0
Example:
MOVAL,'A'AL=01000001b
ORAL,00100000bAL=01100001b('a')
RET
C ZSO PA
0 r r 0 r ?
OUTim.byte,AL
im.byte,AX
DX,AL
DX,AXOutputfromALorAXtoport.
Firstoperandisaportnumber.Ifrequiredtoaccessportnumberover255DXregister
shouldbeused.
Example:
MOVAX,0FFFhTurnonall
OUT4,AXtrafficlights.
MOVAL,100bTurnonthethird

OUT7,ALmagnetofthesteppermotor.
C ZSO PA
unchanged
POPREG
SREG
memoryGet16bitvaluefromthestack.
Algorithm:
operand=SS:[SP](topofthestack)
SP=SP+2
Example:
MOVAX,1234h
PUSHAX
POPDXDX=1234h
RET
C ZSO PA
unchanged
POPANooperandsPopallgeneralpurposeregistersDI,SI,BP,SP,BX,DX,CX,AXfrom
thestack.
SPvalueisignored,itisPoppedbutnotsettoSPregister).
Note:thisinstructionworksonlyon80186CPUandlater!
Algorithm:
POPDI
POPSI
POPBP
POPxx(SPvalueignored)
POPBX
POPDX
POPCX
POPAX
C ZSO PA
unchanged
POPFNooperandsGetflagsregisterfromthestack.
Algorithm:
flags=SS:[SP](topofthestack)
SP=SP+2
C ZSO PA
popped
PUSHREG
SREG
memory

immediateStore16bitvalueinthestack.
Note:PUSHimmediateworksonlyon80186CPUandlater!
Algorithm:
SP=SP2
SS:[SP](topofthestack)=operand
Example:
MOVAX,1234h
PUSHAX
POPDXDX=1234h
RET
C ZSO PA
unchanged
PUSHANooperandsPushallgeneralpurposeregistersAX,CX,DX,BX,SP,BP,SI,DIin
thestack.
OriginalvalueofSPregister(beforePUSHA)isused.
Note:thisinstructionworksonlyon80186CPUandlater!
Algorithm:
PUSHAX
PUSHCX
PUSHDX
PUSHBX
PUSHSP
PUSHBP
PUSHSI
PUSHDI
C ZSO PA
unchanged
PUSHFNooperandsStoreflagsregisterinthestack.
Algorithm:
SP=SP2
SS:[SP](topofthestack)=flags
C ZSO PA
unchanged
RCLmemory,immediate
REG,immediate
memory,CL
REG,CLRotateoperand1leftthroughCarryFlag.Thenumberofrotatesissetbyoperand2.
Whenimmediateisgreaterthen1,assemblergeneratesseveralRCLxx,1instructions
because8086hasmachinecodeonlyforthisinstruction(thesameprincipleworksforall
othershift/rotateinstructions).

Algorithm:
shiftallbitsleft,thebitthatgoesoffissettoCFandpreviousvalueofCFisinsertedtothe
rightmostposition.
Example:
STCsetcarry(CF=1).
MOVAL,1ChAL=00011100b
RCLAL,1AL=00111001b,CF=0.
RET
C O
r r
OF=0iffirstoperandkeepsoriginalsign.RCRmemory,immediate
REG,immediate
memory,CL
REG,CLRotateoperand1rightthroughCarryFlag.Thenumberofrotatesissetby
operand2.
Algorithm:
shiftallbitsright,thebitthatgoesoffissettoCFandpreviousvalueofCFisinsertedtothe
leftmostposition.
Example:
STCsetcarry(CF=1).
MOVAL,1ChAL=00011100b
RCRAL,1AL=10001110b,CF=0.
RET
C O
r r
OF=0iffirstoperandkeepsoriginalsign.REPchaininstruction
RepeatfollowingMOVSB,MOVSW,LODSB,LODSW,STOSB,STOSWinstructionsCX
times.
Algorithm:
check_cx:
ifCX<>0then
dofollowingchaininstruction
CX=CX1
gobacktocheck_cx
else
exitfromREPcycle
Z
r

REPEchaininstruction
RepeatfollowingCMPSB,CMPSW,SCASB,SCASWinstructionswhileZF=1(resultis
Equal),maximumCXtimes.
Algorithm:
check_cx:
ifCX<>0then
dofollowingchaininstruction
CX=CX1
ifZF=1then:
gobacktocheck_cx
else
exitfromREPEcycle
else
exitfromREPEcycle

Z
r
REPNEchaininstruction
RepeatfollowingCMPSB,CMPSW,SCASB,SCASWinstructionswhileZF=0(resultisNot
Equal),maximumCXtimes.
Algorithm:
check_cx:
ifCX<>0then
dofollowingchaininstruction
CX=CX1
ifZF=0then:
gobacktocheck_cx
else
exitfromREPNEcycle
else
exitfromREPNEcycle
Z
r
REPNZchaininstruction
RepeatfollowingCMPSB,CMPSW,SCASB,SCASWinstructionswhileZF=0(resultisNot
Zero),maximumCXtimes.
Algorithm:
check_cx:
ifCX<>0then
dofollowingchaininstruction
CX=CX1
ifZF=0then:

gobacktocheck_cx
else
exitfromREPNZcycle
else
exitfromREPNZcycle
Z
r
REPZchaininstruction
RepeatfollowingCMPSB,CMPSW,SCASB,SCASWinstructionswhileZF=1(resultis
Zero),maximumCXtimes.
Algorithm:
check_cx:
ifCX<>0then
dofollowingchaininstruction
CX=CX1
ifZF=1then:
gobacktocheck_cx
else
exitfromREPZcycle
else
exitfromREPZcycle
Z
r
RETNooperands
orevenimmediateReturnfromnearprocedure.
Algorithm:
Popfromstack:
IP
ifimmediateoperandispresent:SP=SP+operand
Example:
#make_COM#
ORG100hforCOMfile.
CALLp1
ADDAX,1
RETreturntoOS.
p1PROCproceduredeclaration.
MOVAX,1234h
RETreturntocaller.
p1ENDP
C ZSO PA
unchanged

RETFNooperands
orevenimmediateReturnfromFarprocedure.
Algorithm:
Popfromstack:
IP
CS
ifimmediateoperandispresent:SP=SP+operand
C ZSO PA
unchanged
ROLmemory,immediate
REG,immediate
memory,CL
REG,CLRotateoperand1left.Thenumberofrotatesissetbyoperand2.
Algorithm:
shiftallbitsleft,thebitthatgoesoffissettoCFandthesamebitisinsertedtotherightmost
position.
Example:
MOVAL,1ChAL=00011100b
ROLAL,1AL=00111000b,CF=0.
RET
C O
r r
OF=0iffirstoperandkeepsoriginalsign.RORmemory,immediate
REG,immediate
memory,CL
REG,CLRotateoperand1right.Thenumberofrotatesissetbyoperand2.
Algorithm:
shiftallbitsright,thebitthatgoesoffissettoCFandthesamebitisinsertedtotheleftmost
position.
Example:
MOVAL,1ChAL=00011100b
RORAL,1AL=00001110b,CF=0.
RET
C O
r r
OF=0iffirstoperandkeepsoriginalsign.SAHFNooperandsStoreAHregisterintolow8
bitsofFlagsregister.
Algorithm:

flagsregister=AH
AHbit:76543210
[SF][ZF][0][AF][0][PF][1][CF]
bits1,3,5arereserved.
C ZSO PA
r r r r r r
SALmemory,immediate
REG,immediate
memory,CL
REG,CLShiftArithmeticoperand1Left.Thenumberofshiftsissetbyoperand2.
Algorithm:
Shiftallbitsleft,thebitthatgoesoffissettoCF.
Zerobitisinsertedtotherightmostposition.
Example:
MOVAL,0E0hAL=11100000b
SALAL,1AL=11000000b,CF=1.
RET
C O
r r
OF=0iffirstoperandkeepsoriginalsign.SARmemory,immediate
REG,immediate
memory,CL
REG,CLShiftArithmeticoperand1Right.Thenumberofshiftsissetbyoperand2.
Algorithm:
Shiftallbitsright,thebitthatgoesoffissettoCF.
Thesignbitthatisinsertedtotheleftmostpositionhasthesamevalueasbeforeshift.
Example:
MOVAL,0E0hAL=11100000b
SARAL,1AL=11110000b,CF=0.
MOVBL,4ChBL=01001100b
SARBL,1BL=00100110b,CF=0.
RET
C O
r r
OF=0iffirstoperandkeepsoriginalsign.SBBREG,memory
memory,REG
REG,REG

memory,immediate
REG,immediateSubtractwithBorrow.
Algorithm:
operand1=operand1operand2CF
Example:
STC
MOVAL,5
SBBAL,3AL=531=1
RET
C ZSO PA
r r r r r r
SCASBNooperandsComparebytes:ALfromES:[DI].
Algorithm:
ES:[DI]AL
setflagsaccordingtoresult:
OF,SF,ZF,AF,PF,CF
ifDF=0then
DI=DI+1
else
DI=DI1
C ZSO PA
r r r r r r
SCASWNooperandsComparewords:AXfromES:[DI].
Algorithm:
ES:[DI]AX
setflagsaccordingtoresult:
OF,SF,ZF,AF,PF,CF
ifDF=0then
DI=DI+2
else
DI=DI2
C ZSO PA
r r r r r r
SHLmemory,immediate
REG,immediate
memory,CL
REG,CLShiftoperand1Left.Thenumberofshiftsissetbyoperand2.
Algorithm:
Shiftallbitsleft,thebitthatgoesoffissettoCF.

Zerobitisinsertedtotherightmostposition.
Example:
MOVAL,11100000b
SHLAL,1AL=11000000b,CF=1.
RET
C O
r r
OF=0iffirstoperandkeepsoriginalsign.SHRmemory,immediate
REG,immediate
memory,CL
REG,CLShiftoperand1Right.Thenumberofshiftsissetbyoperand2.
Algorithm:
Shiftallbitsright,thebitthatgoesoffissettoCF.
Zerobitisinsertedtotheleftmostposition.
Example:
MOVAL,00000111b
SHRAL,1AL=00000011b,CF=1.
RET
C O
r r
OF=0iffirstoperandkeepsoriginalsign.STCNooperandsSetCarryflag.
Algorithm:
CF=1
C
1
STDNooperandsSetDirectionflag.SIandDIwillbedecrementedbychaininstructions:
CMPSB,CMPSW,LODSB,LODSW,MOVSB,MOVSW,STOSB,STOSW.
Algorithm:
DF=1
D
1
STINooperandsSetInterruptenableflag.Thisenableshardwareinterrupts.
Algorithm:
IF=1

I
1
STOSBNooperandsStorebyteinALintoES:[DI].UpdateSI.
Algorithm:
ES:[DI]=AL
ifDF=0then
DI=DI+1
else
DI=DI1
Example:
#make_COM#
ORG100h
LEADI,a1
MOVAL,12h
MOVCX,5
REPSTOSB
RET
a1DB5dup(0)
C ZSO PA
unchanged
STOSWNooperandsStorewordinAXintoES:[DI].UpdateSI.
Algorithm:
ES:[DI]=AX
ifDF=0then
DI=DI+2
else
DI=DI2
Example:
#make_COM#
ORG100h
LEADI,a1
MOVAX,1234h
MOVCX,5
REPSTOSW
RET
a1DW5dup(0)
C ZSO PA

unchanged
SUBREG,memory
memory,REG
REG,REG
memory,immediate
REG,immediateSubtract.
Algorithm:
operand1=operand1operand2
Example:
MOVAL,5
SUBAL,1AL=4
RET
C ZSO PA
r r r r r r
TESTREG,memory
memory,REG
REG,REG
memory,immediate
REG,immediateLogicalANDbetweenallbitsoftwooperandsforflagsonly.Theseflagsare
effected:ZF,SF,PF.Resultisnotstoredanywhere.
Theserulesapply:
1AND1=1
1AND0=0
0AND1=0
0AND0=0
Example:
MOVAL,00000101b
TESTAL,1ZF=0.
TESTAL,10bZF=1.
RET
C ZSO P
0 r r 0 r
XCHGREG,memory
memory,REG
REG,REGExchangevaluesoftwooperands.
Algorithm:
operand1<>operand2
Example:

MOVAL,5
MOVAH,2
XCHGAL,AHAL=2,AH=5
XCHGAL,AHAL=5,AH=2
RET
C ZSO PA
unchanged
XLATBNooperandsTranslatebytefromtable.
CopyvalueofmemorybyteatDS:[BX+unsignedAL]toALregister.
Algorithm:
AL=DS:[BX+unsignedAL]
Example:
#make_COM#
ORG100h
LEABX,dat
MOVAL,2
XLATBAL=33h
RET
datDB11h,22h,33h,44h,55h
C ZSO PA
unchanged
XORREG,memory
memory,REG
REG,REG
memory,immediate
REG,immediateLogicalXOR(ExclusiveOR)betweenallbitsoftwooperands.Resultis
storedinfirstoperand.
Theserulesapply:
1XOR1=0
1XOR0=1
0XOR1=1
0XOR0=0
Example:
MOVAL,00000111b
XORAL,00000010bAL=00000101b
RET
C ZSO PA
0 r r 0 r ?

Copyright20032005Emu8086,Inc.
Allrightsreserved.
http://www.emu8086.com

Das könnte Ihnen auch gefallen