Vous êtes sur la page 1sur 3

7/7/2015

ProgramControlInstructions

ProgrammeControlInstructions
INTRODUCTION
Theprogrammecontrolinstructionsdirecttheflowofaprogrammeandallowtheflowofthe
programmetochange.Achangeinflowoftenoccurswhendecisions,madewiththeCMPor
TESTinstruction,arefollowedbyaconditionaljumpinstruction.
THEJUMPGROUP
Themaintypeofprogrammecontrolinstruction,thejump(JMP),allowstheprogrammemerto
skipsectionsofaprogrammeandbranchtoanypartofthememoryforthenextinstruction.A
conditionaljumpinstructionallowstheprogrammemertomakedecisionsbaseduponnumerical
tests.Theresultsofthesenumericaltestsareheldintheflagbits,whicharethentestedby
conditionaljumpinstructions.

UnconditionalJump
Threetypesofunconditionaljumpinstructionsareavailableinthemicroprocessor'sinstruction
set:shortjump,nearjump,andfarjump.
Theshortjumpisa2byteinstructionthatallowsjumpsorbranchestomemorylocationswithin
+127and128bytesfromthememorylocationfollowingthejump.The3bytenearjumpallows
abranchorjumpwithin32Kbytes(anywhere)fromtheinstructioninthecurrentcode
segment.Finally,the5bytefarjumpallowsajumptoanymemorylocationwithintheentire
memorysystem.Theshortandnearjumpsareoftencalledintrasegmentjumpsandthefar
jumpsareoftencalledintersegmentjumps.

ShortJump.Shortjumpsarecalledrelativejumpsbecausetheycanbemovedanywherein
currentcodesegmentwithoutachange.Thisisbecauseajumpaddressisnotstoredwiththe
opcode.Insteadofajumpaddress,adistance,ordisplacement,followstheopcode.Theshort
jumpdisplacementisadistancerepresentedbya1bytesignednumberwhosevalueranges
between+127and128.
OPCODE(EB)

Displacement
(+127to128)

Whenthemicroprocessorexecutesashortjump,thedisplacementsignextendsandaddsto
theinstructionpointer(IP)togeneratethejumpaddresswithinthecurrentcodesegment.The
shortjumpinstructionbranchestothisnewaddressforthenextinstructioninthe
programmeme.
http://www.electronics.dit.ie/staff/tscarff/program_control/program_control.htm

1/3

7/7/2015

ProgramControlInstructions

Wheneverajumpinstructionreferencesanaddress,alabelidentifiestheaddress.TheJMP
NEXTisanexample,whichjumpstolabelNEXTforthenextinstruction.Weneverusean
actualhexadecimaladdresswithanyjumpinstruction.ThelabelNEXTmustbefollowedbya
colon(NEXT:)toallowaninstructiontoreferenceitforajump.Ifacolondoesnotfollowa
label,youcannotjumptoit.Notethattheonlytimeweeveruseacolonafteralabeliswhen
thelabelisusedwithajumporcallinstruction.

NearJump.Thenearjumpissimilartotheshortjumpexceptthedistanceisfarther.Anear
jumppassescontroltoaninstructioninthecurrentcodesegmentlocatedwithin32Kbytes
fromthenearjumpinstruction.Thenearjumpisa3byteinstructionthatcontainsanopcode
followedbyasigned16bitdisplacement.Thesigneddisplacementaddstotheinstruction
pointer(IP)togeneratethejumpaddress.Becausethesigneddisplacementisintherangeof
32K,anearjumpcanjumptoanymemorylocationwithinthecurrentrealmodecode
segment.
OPCODE(E9)

DISPLACEMENT

DISPLACEMENT

LowByte

HighByte

FarJump.Thefarjumpobtainsanewsegmentandoffsetaddresstoaccomplishthejump.
Bytes2and3ofthis5byteinstructioncontainthenewoffsetaddressandbytes4and5
containthenewsegmentaddress,withtheLowBytefollowedbytheHighByteinbothcases.
OPCODE(EA)

IP

IP

CS

CS

LowByte

HighByte

LowByte

HighByte

ConditionalJumps
Conditionaljumpsarealwaysshortjumpsinthe8086microprocessor.Thislimitstherangeof
thejumptowithin+127bytesand128bytesfromthelocationfollowingtheconditionaljump.
Theconditionaljumpinstructionstestthefollowingflagbits:sign(S),zero(Z),carry(C),parity
(P),andoverflow(0).Iftheconditionundertestistrueabranchtothelabelassociatedwiththe
jumpinstructionoccurs.Iftheconditionisfalse,thenextsequentialstepintheprogramme
executes.
Theoperationofmostconditionaljumpinstructionsisstraightforwardbecausetheyoftentest
justoneflagbit,butsometestmorethanoneflag.Relativemagnitudecomparisonsrequire
morecomplicatedconditionaljumpinstructionsthattestmorethanoneflagbit.
Becauseweusebothsignedandunsignednumbers,andtheorderofthesenumbersis
http://www.electronics.dit.ie/staff/tscarff/program_control/program_control.htm

2/3

7/7/2015

ProgramControlInstructions

different,therearetwosetsofmagnitudecomparisonconditionaljumpinstructions,bothsigned
andunsigned8bitnumbers.
The16and32bitnumbersfollowthesameorderasthe8bitnumbersexcepttheyarelarger.
NoticethatanFFHisabovethe00Hinthesetofunsignednumbers,butanFFH(1)isless
than00Hforsignednumbers.Therefore,anunsignedFFHisabove00H,butasignedFFHis
lessthan00H.
Whenwecomparesignednumbers,weuseJG,JE,JGE,JLE,JE,andJNE.Thetermsgreater
thanandlessthanrefertosignednumbers.Whenwecompareunsignednumbers,weuseJA,
JB,JAE,JBE,JE,andJNE.Thetermsaboveandbelowrefertounsignednumbers.
Theremainingconditionaljumpstestindividualflagbitssuchasoverflowandparity.Noticethat
JEhasanalternativeopcodeJZ.Allinstructionshavealternateopcodes.

LOOP
TheLOOPinstructionisacombinationofadecrementofCXandaconditionaljump.Inthe
8086,LOOPdecrementsCXandifCXisnotequaltozero,itjumpstotheaddressindicatedby
thelabel.IfCXbecomesa0,thenextsequentialinstructionexecutes.
ConditionalLOOPS.TheLOOPinstructionalsohasconditionalLOOPEandLOOPNE.The
LOOPE(loopwhileequal)instructionjumpsifCXisnotequaltozero,whileanequalcondition
exists.ItwillexittheloopiftheconditionisnotequaloriftheCXregisterdecrementsto0.The
LOOPNE(loopwhilenotequal)instructionjumpsifCXisnotequaltozero,whileanotequal
conditionexists.ItwillexittheloopiftheconditionisequaloriftheCXregisterdecrementsto
0.Aswiththeconditionalrepeatinstructions,alternatesexistforLOOPEandLOOPNE.

http://www.electronics.dit.ie/staff/tscarff/program_control/program_control.htm

3/3