7/7/2015
ProgramControlInstructions
ProgrammeControlInstructions
INTRODUCTION
Theprogrammecontrolinstructionsdirecttheflowofaprogrammeandallowtheflowofthe
[Link],madewiththeCMPor
TESTinstruction,arefollowedbyaconditionaljumpinstruction.
THEJUMPGROUP
Themaintypeofprogrammecontrolinstruction,thejump(JMP),allowstheprogrammemerto
skipsectionsofaprogrammeandbranchtoanypartofthememoryforthenextinstruction.A
conditionaljumpinstructionallowstheprogrammemertomakedecisionsbaseduponnumerical
[Link],whicharethentestedby
conditionaljumpinstructions.
UnconditionalJump
Threetypesofunconditionaljumpinstructionsareavailableinthemicroprocessor'sinstruction
set:shortjump,nearjump,andfarjump.
Theshortjumpisa2byteinstructionthatallowsjumpsorbranchestomemorylocationswithin
+127and128bytesfromthememorylocationfollowingthejump.The3bytenearjumpallows
abranchorjumpwithin32Kbytes(anywhere)fromtheinstructioninthecurrentcode
[Link],the5bytefarjumpallowsajumptoanymemorylocationwithintheentire
[Link]
jumpsareoftencalledintersegmentjumps.
[Link]
[Link]
[Link],adistance,ordisplacement,[Link]
jumpdisplacementisadistancerepresentedbya1bytesignednumberwhosevalueranges
between+127and128.
OPCODE(EB)
Displacement
(+127to128)
Whenthemicroprocessorexecutesashortjump,thedisplacementsignextendsandaddsto
theinstructionpointer(IP)[Link]
shortjumpinstructionbranchestothisnewaddressforthenextinstructioninthe
programmeme.
[Link]
1/3
7/7/2015
ProgramControlInstructions
Wheneverajumpinstructionreferencesanaddress,[Link]
NEXTisanexample,[Link]
[Link]
colon(NEXT:)[Link]
label,[Link]
thelabelisusedwithajumporcallinstruction.
[Link]
jumppassescontroltoaninstructioninthecurrentcodesegmentlocatedwithin32Kbytes
fromthenearjumpinstruction.Thenearjumpisa3byteinstructionthatcontainsanopcode
[Link]
pointer(IP)[Link]
32K,anearjumpcanjumptoanymemorylocationwithinthecurrentrealmodecode
segment.
OPCODE(E9)
DISPLACEMENT
DISPLACEMENT
LowByte
HighByte
[Link].
Bytes2and3ofthis5byteinstructioncontainthenewoffsetaddressandbytes4and5
containthenewsegmentaddress,withtheLowBytefollowedbytheHighByteinbothcases.
OPCODE(EA)
IP
IP
CS
CS
LowByte
HighByte
LowByte
HighByte
ConditionalJumps
[Link]
thejumptowithin+127bytesand128bytesfromthelocationfollowingtheconditionaljump.
Theconditionaljumpinstructionstestthefollowingflagbits:sign(S),zero(Z),carry(C),parity
(P),andoverflow(0).Iftheconditionundertestistrueabranchtothelabelassociatedwiththe
[Link],thenextsequentialstepintheprogramme
executes.
Theoperationofmostconditionaljumpinstructionsisstraightforwardbecausetheyoftentest
justoneflagbit,[Link]
morecomplicatedconditionaljumpinstructionsthattestmorethanoneflagbit.
Becauseweusebothsignedandunsignednumbers,andtheorderofthesenumbersis
[Link]
2/3
7/7/2015
ProgramControlInstructions
different,therearetwosetsofmagnitudecomparisonconditionaljumpinstructions,bothsigned
andunsigned8bitnumbers.
The16and32bitnumbersfollowthesameorderasthe8bitnumbersexcepttheyarelarger.
NoticethatanFFHisabovethe00Hinthesetofunsignednumbers,butanFFH(1)isless
[Link],anunsignedFFHisabove00H,butasignedFFHis
lessthan00H.
Whenwecomparesignednumbers,weuseJG,JE,JGE,JLE,JE,[Link]
[Link],weuseJA,
JB,JAE,JBE,JE,[Link].
[Link]
[Link].
LOOP
[Link]
8086,LOOPdecrementsCXandifCXisnotequaltozero,itjumpstotheaddressindicatedby
thelabel.IfCXbecomesa0,thenextsequentialinstructionexecutes.
[Link]
LOOPE(loopwhileequal)instructionjumpsifCXisnotequaltozero,whileanequalcondition
[Link]
LOOPNE(loopwhilenotequal)instructionjumpsifCXisnotequaltozero,whileanotequal
[Link]
[Link],alternatesexistforLOOPEandLOOPNE.
[Link]
3/3