《微机原理及应用实践(英文版)》Chapter 3  INSTRUCTION SYSTEM_第1页
《微机原理及应用实践(英文版)》Chapter 3  INSTRUCTION SYSTEM_第2页
《微机原理及应用实践(英文版)》Chapter 3  INSTRUCTION SYSTEM_第3页
《微机原理及应用实践(英文版)》Chapter 3  INSTRUCTION SYSTEM_第4页
《微机原理及应用实践(英文版)》Chapter 3  INSTRUCTION SYSTEM_第5页
已阅读5页,还剩253页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Chapter3INSTRUCTIONSYSTEM3.1AddressingModes3.2InstructionFormandCode3.3InstructionSet3.4TroubleShootingTechniquesOBJECTIVES

Uponfinishingthischapter,youwilllearn:

Thewaysthatmicroprocessorslocatethedatawheretobestoredandhowtobebroughtbyaninstruction.

Instructioncodeshowtoencodeanddecodeby80x86.

3.1AddressingModes

Amicroprocessorinstructionisabinaryword.Whenitisreadasaninstruction,thisbinarywordtellsthemicroprocessortodoonesimpletask.Nootherbinarywordtellsthemicroprocessortodothistask.Mostmicroprocessorinstructionsletyoumoveorprocessdata.Thedatamaybeinmemory,oritmaybeinoneofthemicroprocessor’sregisters.Afewothermicroprocessorinstructionsletyoudo“housekeeping”functions.

Theseinstructionsletyoucontrolcertainmicroprocessorinstructions.1Aninstructioncanbebrokenintotwoparts,calledtheopcode(operationcode)andtheoperands.Theopcodetellsthemicroprocessorwhattodo,andtheoperandtellsitthecontentofthisdoingaction.Oftenyouwillfindthatthefirstwordofamultiwordinstructionistheopcode.Eitherthesecondwordorthesecondandthirdwordsareoperands.

Themicroprocessor’saddressingmodesarethewaythatthemicroprocessoridentifiesthelocationoftheoperandsordata.Whenthe8086executesaninstruction,itperformsthespecifiedfunctionindata.Thesedata,calledoperands,maybeonepartoftheinstruction,mayresideinoneoftheinternalregistersofthemicroprocessor,maybestoredatanaddressinmemory,ormaybeheldatanI/Oport.Aswewillsee,thenormalmicroprocessorhasmanydifferentwaysanditcanidentifydatainaparticularlocation.

Eachdifferentwaymaybeusedatadifferenttime,dependingonothercircumstances.2Toaccessthesedifferenttypesofoperands,the8086isprovidedwithvariousaddressingmodeswhicharecategorizedintothreetypes:registeroperandaddressing,immediateoperandaddressing,andmemoryoperandaddressing.Letusnowconsiderindetailtheaddressingmodesineachofthesecategories.3.1.1RegisterAddressing

Withtheregisteraddressingmode,theoperandtobeaccessedisspecifiedasresidinginaninternalregisterofthe8086.Table3.1liststheinternalregistersthatcanbeusedasasourceoradestinationoperand.Notethatonlythedataregisterscanbeaccessedaseitherabyteoraword.

Anexampleofaninstructionthatusesthisaddressingmodeis

MOVAX,BX

Thisstandsfor“moveorcopythecontentsofBX,whichisthesourceoperand,toAX,whichisthedestinationoperand.”Boththesourceanddestinationoperandshavebeenspecifiedasthewordcontentsofinternalregisterofthe8086.

Letusnowlookattheeffectofexecutingmoveinstructionintheregisteraddressingmove.InFigure3.1(a),weseethestateofthe8086justpriortofetchingtheinstruction.NotethatthelogicaladdressformedfromCSandIP(CS:IP)pointstothe“MOVAX,BX”instructionatphysicaladdress01000H.Thisinstructionisfetchedintothe8086’sinstructionqueue,whereitisheldwaitingtobeexecuted.

Priortoexecutionofthisinstruction,thecontentsofBXareABCDH,andthecontentsofAXrepresentadon’t-carestate.Theinstructionisreadfromtheoutputsideofthequeue,thendecoded,andexecuted.AsFigure3.1(b)shows,theresultproducedbyexecutingthisinstructionisthatthevalueABCDHiscopiedintoAX,andtheIP=IP+2pointsto01002H.Figure3.1(a)Registeraddressingmodeinstructionbeforefetchingandexecution;(b)Afterexecution

Single-byteinstructionsexecutefasterthananyotherinstructions.Themicroprocessormustcompletetheexecutionofaninstruction.Asingle-byteinstructionisexecutionofaninstruction,anditisexecutedintwomicroprocessorcycles.Thefetchingtakesonecycle,andtheexecutiontakestheothercycle.

Asyougoon,paycloseattentiontohowmanymicroprocessorcyclesareneededtocarryouttheinstructionsthatuseotheraddressingmodes.Youwillseethattheinstructionsusingtheinherentaddressingmodearethefastestinstructions.

3.1.2ImmediateAddressing

Immediateaddressingiseasytounderstand.Immediatelyfollowingtheopcodearethedata.Sotheinstructionwillbeencodedwithanimmediateoperand.Theremaybeeitheroneortwobytesofdata.Thesedataaresuppliedbytheprogrammer.Immediateaddressing,therefore,requiresnomemoryaddress.Theoperandisonepartoftheinstructioninsteadofthecontentsofaregisterormemorylocation,itrepresentswhatiscalledanimmediateoperand.

Sincethedataareencodeddirectlyintotheinstruction,immediateoperandsnormallyrepresentconstantdata.Immediateaddressingrequiresonlyanopcodeimmediatelyfollowedbythedatatobeoperatedon.Thisaddressingmodecanonlybeusedtospecifyasourceoperand.

Intheinstruction:

MOVAL,15H

Thesourceoperand15Hisanexampleofabyte-wideimmediatesourceoperand.Thedestinationoperand,whichisthecontentsofAL,usesregisteraddressing.Thus,thisinstructionemploysboththeimmediateandregistersaddressingmodes.

Figure3.2(a)and(b)illustratethefetchandexecutionofthisinstruction.Herewefindthattheimmediateoperand15Hisstoredinthecodesegmentofmemoryinthebytelocationimmediatelyfollowingtheopcodeoftheinstruction.Thisvalueisfetched,alongwiththeopcodeforMOV,intotheinstructionqueuewithinthe8086.Whenitperformsthemoveoperation,thesourceoperandisfetchedfromthequeue,notfromthememory,andnoexternalmemoryoperationsareperformed.Notethattheresultproducedbyexecutingthisinstructionisthattheimmediateoperand,whichequals15H,isloadedintothelower-bytepartoftheaccumulator(AL).Figure3.2(a)Immediateaddressingmodeinstructionbeforefetchandexecution;(b)Afterexecution

[ReadingMaterial]Whenisimmediateaddressinguseful?Agoodexampleisaprogramthatrequiresloadingtheaccumulatorwiththesame8-bitnumbereachtimetheprogramisrun.Intheinstruction’sfirstbyte,youputtheopcodethattellsthemicroprocessortoloaditsaccumulatorwiththecontentsofthebytethatimmediatelyfollowstheopcode.Inthatsecondbyte,youputthedatayouwantintotheaccumulator.

Theinstructionasisdescribedaboveiscalledtheregisterimmediateinstruction.Figure3.3showshowtheloadregisterimmediateinstructionappearswhenitisinmemory.Itshowsthe

opcodeintheinstruction’sfirstbyteandthedataintheinstruction’ssecondbyte.Ofcourse,boththeopcodeandthedatawillcontainbinaryinformationratherthanthenamesusedinFigure3.3.Figure.3.3Theloadregisterimmediateinstruction,wherethedataisinabytefollowingtheopcodebyte

Theimmediateaddressingmodeusestwomicroprocessorcycles.Duringthefirstcycle,theinstructionisfetched.Whentheinstructionisexecuted,thesecondbyte(thedata)isprocessedaccordingtowhatthefirstbyte(theopcode)tellsthemicroprocessor’slogictodo.

Inimmediateaddressing,thedatamustimmediatelyfollowtheinstructioninmemory.Thatis,thedataisactuallypartofthemicroprocessor’sinstruction.Butamicroprocessoroftenneedstouseinformationstoredatothermemorylocations.Insuchcasesimmediateaddressingwillnotworkinsuchcases,whichleadsustothenextformofaddressing.3.1.3MemoryAddressing

Toaccessanoperandinmemory,the8086/8088mustcalculatethephysicaladdressoftheoperandandtheninitiateareadorwriteoperationofthisstoragelocation.The8086/8088CPUisprovidedwithagroupofaddressingmodesknownasthememoryoperandaddressingmodesforthispurpose.LookingatFigure3.4,weseethatthephysicaladdressiscomputedfromasegmentbaseaddress(SBA)andaneffectiveaddress(EA).

SBAidentifiesthestartinglocationofthesegmentinmemory,andEArepresentstheoffsetoftheoperandfromthebeginningofthissegmentofmemory.EarlierweshowedhowSBAandEAarecombinedwithinthe8086/8088toformthelogicaladdressSBA:EAandhowtocomputethephysicaladdressfromthesetwovalues.

ThevalueoftheEAcanbespecifiedinavarietyofways.Onewayistoencodetheeffectiveaddressoftheoperanddirectlyintheinstruction.Thisrepresentsthesimplesttypeofmemoryaddressing,knownasthedirectaddressingmode.Figure3.4showsthataneffectiveaddresscanbemadeupfromasmanyasthreeelements:thebase,index,anddisplacement.Usingtheseelements,theeffectiveaddresscalculationismadebythegeneralformula

EA=Base+Index+Displacement

Figure3.4alsoidentifiestheregistersthatcanbeusedtoholdthevaluesofthesegmentbase,base,andindex.Forexample,3ittellsusthatanyofthefoursegmentregistercanbethesourceofthesegmentbaseforthephysicaladdresscalculationandthatthevalueofbasefortheeffectiveaddresscanbeineitherthebaseregister(BX)orbasepointregister(BP).Italsoidentifiesthesizespermittedforthedisplacement.Figure3.4Physicalandeffectiveaddresscomputationformemoryoperands

Notalltheseelementsarealwaysusedincalculatingtheeffectiveaddress.Infact,anumberofmemoryaddressingmodesaredefinedbyusingvariouscombinationsoftheseelementswhatwecanselectinFigure3.5.Theyarecalleddirectaddressing,registerindirectaddressing,basedaddressing,

indexedaddressing,

and

based-indexedaddressing.Forinstance,usingbasedaddressingmode,theeffectiveaddresscalculationincludesjustabase.Theseaddressingmodesprovidetheprogrammerwithdifferentwaysofcomputingtheeffectiveaddressofanoperandinmemory.Next,wewillexamineeachofthememoryoperandaddressingmodesindetail.

1.Directaddressing

Instructionsthatusedirectaddressingmayhave2or3bytes.Frequently,thesearereferredtoastwodifferentaddressingmodes.Thefirstbyteoftheseinstructionsistheopcode.Thesecondbyteand,ifpresent,thethirdbyteareamemoryaddress.Thememoryaddresspointstothememorylocationthatcontainsthedatatobeworkedon.Thesecondandthirdbytescanaddresstheentire65,536memorylocationsinan8-bitmicroprocessor.Ina16-bitmicroprocessor,thesecondandthirdwordsallowthemicroprocessortoaddressthefulladdressrangeof4Gbytes.

Directaddressingisinmanywaystheeasiestaddressingmodetounderstand.Ininherentaddressing,theaddressis“builtin”.Theprogrammerdoesnothavetoaddressamemorylocationtogetdata.Inimmediateaddressing,thedataisfoundinthebyteimmediatelyfollowingtheopcode.Again,theprogrammerdoesnothavetoaddressamemorylocationtogetthedata;thedataisbuiltintotheinstruction.Indirectaddressing,however,theprogrammeris,forthefirsttime,actuallygivingtheaddressofthememorylocationwheretheneededdataislocated.

AsFigure3.6shows,thiseffectiveaddressisuseddirectlyasthe16-bitoffsetofthestoragelocationoftheoperandfromthelocationspecifiedbythecurrentvalueintheselectedsegmentregisterinFigure3.5.ThedefaultsegmentisDS.Therefore,the20-bitphysicaladdressoftheoperandinmemoryisnormallyobtainedfromlogicaladdressDS:EA.But,byusingasegmentoverrideprefix(SOP)intheinstruction,anyofthefoursegmentregisterscanbereferenced.Figure3.5Specificationofadirectmemoryaddress

Anexampleofaninstructionthatusesdirectaddressingmodeforitssourceoperandis

MOVCX,[1234H]

Thisstandsfor“movethecontentsofthememorylocationwithoffset1234HinthecurrentdatasegmentintointernalregisterCX.”Theoffsetisencodedaspartoftheinstruction’smachinecode.

InFigure3.6(a),wefindthattheoffsetisstoredinthetwobytelocationsthatfollowtheinstruction’sopcode.Astheinstructionisexecuted,the8088combines1234Hwith0200Htogetthephysicaladdressofthesourceoperandasfollows:

PA=0200016+123416=0323416

Thenitreadsthewordofdatastartingatthisaddress,whichisBEEDH,andloadsitintotheCXregister.ThisresultisillustratedinFigure3.6(b).Figure3.6(a)Directaddressingmodeinstructionbeforefetchandexecution;(b)Afterexecution

Whenyouusedirectaddressing,youuseextramicroprocessorcycles.Inthemicroprocessorcycles,firstlythemicroprocessormustfetchtheinstruction’sopcode.Whentheinstructionisdecoded,themicroprocessorknowsthatitmustfetchanadditional2bytesofinformation.Thesebytesofdatamakeuptheaddressofthememorylocationwherethedataisstored.Eachadditionalfetchtakesonemoremicroprocessorcycle.

Oncetheopcodeandthe2addressbytesarefetched,themicroprocessorstillmustexecutetheinstruction.Thistakesafourthmicroprocessorcycle.

Fromthisyoucanseethatexecutinganinstructionwithdirectaddressingtakestwiceaslongasexecutinganinstructionwithimmediateaddressing.Ofcourse,directaddressingisnecessarywhenyouneedtoplacedataatanylocationinmemory.

[ReadingMaterial]Whenyouwriteprograms,youshoulduseasfewdirectaddressinginstructionsaspossiblebecausetheytakelongertoexecute.Thisisespeciallytruewhenyouarewritingspecificpartsofaprogramwhichmustoperateatveryhighspeeds.Frequentlywhenwritingthistypeofprogram,aprogrammerwillchangefromahigh-levellanguagetoanassembly-levellanguagetoensurethatuseoftime-consuminginstructions,suchasthedirectinstructions,islimited.

Asingledatawordinan8-bitmicroprocessorisnotlongenoughtoaddressa64Kwordmemorylocation.Inan8-bitwordusedinthesecondbyteoftheinstructioncanonlyaddress256memorylocations.Toovercomethis,aspecialopcodetellsyouthattheinstructionisaspecialformofdirectaddressinstructionwhichusesasingleaddressbyte.

Usually,thesesingle-byteaddressesstartatthe“bottom”ofmemory.Thatis,theystartataddresslocation0000H.Sometimesthissingle-byterangeofmemoryiscalledmemorypage0.Forexample,an8-bitmicroprocessorusingasinglebyteofaddressinformationmightaddressthefirst256memorylocations.Thesearememorylocations0to255(00H-FFH).Ontheotherhand,the2-byteaddresswordaddressesthefirst65,536(0000HtoFFFFH).

Whatistheadvantageofdirectaddressinglimitedtoone-wordaddresses?Theansweristhatitsavesmicroprocessorcycles.Itsavestime.Thiscanbeavaluableaddressingmodeforboth8-and16-bitmicroprocessorsiftherearefewbytesofdatathatmustbeaddressedfrequently.Thesefewbytesofdatacanbestoredinthefirst256bytesofmemoryinan8-bitmicroprocessor.Ofcourse,ina16-bitmicroprocessorthesesingle-addresswordinstructionscanaddressthefirst65,536memorylocations,andarethereforeveryuseful.

Howdoyoutellthetwoaddressingmodesapartifthemicroprocessorhasbothtwo-andthree-worddirectaddressinginstructions?Themanufacturergiveseachformofdirectaddressingadifferentname.Infact,manymicroprocessormanufacturerstreatthesetwoformsofdirectaddressingastwocompletelydifferentaddressingmodes.Theopcodesfortheseformsofaddressingarealsodifferent.Forexample,somemanufacturerscall2-bytedirectaddressingdirectaddressingofpage0addressingandrefertothe3-bytedirectaddressingasextendeddirectaddressing.

2. Registerindirectaddressing

Intheregisterindirectaddressingmode,theinstructioncontainstheopcodeandalsoindicateswhichregisterpointstothememorylocationcontainingtheneededdata.Thatis,theinstructiondoesnotcontainthedata,asinimmediateaddressing,ortheaddressofthedata,asindirectaddressing.Buttheinstructionindicateswhichregistercontainstheneededdata.Dependingonthesizeofthemicroprocessor’saddressspace,theregisterindirectaddressingmodemayindicatearegisterpairwhichpointstothecorrectmemoryaddress.

Registerindirectaddressingmodeissimilartothedirectaddressingwejustdescribedinbothofthem,whichmeansaneffectiveaddressiscombinedwiththecontentsofDStoobtainaphysicaladdress.However,theydifferinthewaythattheoffsetisspecified.Figure3.7showsthatthistimeEAresidesineitherabaseregisteroranindexregisterwithinthe8088.ThebaseregistercanbeeitherbaseregisterBXorbasepointerregisterBP,andtheindexregistercanbesourceindexregisterSIordestinationindexregisterDI.Useofasegmentoverrideprefixpermitsaccessofanothersegmentregister.Figure3.7Specificationofanindirectmemoryaddress

Anexampleis

MOVAX,[SI]

ExecutionofthisinstructionmovesthecontentsofthememorylocationthatisoffsetfromthebeginningofthecurrentdatasegmentbythevalueofEAinregisterSIintotheAXregister.

Forinstance,Figure3.8(a)and(b)showthatifSIcontains1234HandDScontains0200H,theresultafterexecutingtheinstructionisthatthecontentsofthememorylocationataddress

PA=0200016+123416=0323416

aremovedtotheAXregister.NoticeinFigure3.8(b)thatthisvalueisBEEDH.Inthisexample,thevalue1234HintheSIregistermusthavebeenloadedwithanotherinstructionpriortoexecutingthemoveinstruction.IfgiveMOVAX,ES:[SI],thenPA=120016+123416=1323416,AX=BAADHinsteadofBEEDH.Figure3.8(a)Instructionusingregisterindirectaddressingmodebeforefetchandexecution;(b)Afterexecution

Theresultproducedbyexecutingthisinstructionandthatfortheexampleforthedirectaddressingmodearethesame.However,theydifferinthewaytogeneratetheirphysicaladdress.ThedirectaddressingmethodlendsitselftoapplicationswherethevalueofEAisaconstant.Ontheotherhand,registerindirectaddressingcanbeusedwhenthevalueofEAiscalculatedandstored,forexample,inSIbyapreviousinstruction—thatis,EAisavariable.Forinstance,theinstructionsexecutedjustbeforeourexampleinstructioncouldhaveincrementedthevalueinSIbytwo.

[ReadingMaterial]Indirectaddressingisveryconvenientformovingdatatoandfromfrequentlyusedmemorylocations.Thisisespeciallytruewhenthedataisinlistorfileformat.Thatis,itisveryhelpfulwhenyouwanttostoreorreaddatainsequentialmemorylocations.

Aprogramthatfilesdatainsequentiallocations(onelocationafterthenext)isshowninFigure3.9.Thisprogramusesregisterindirectaddressing.ItinputsdatafromanI/Oporttotheaccumulator.Thedataisthenstoredinsequentialmemorylocations.Thisexamplemayuseinstructionsthatyoudonotyetfullyunderstand.Whatyouneedtoseehereishowtheindirectmemoryaddressingmodeisused.

Theprogramisshowninflowchartform.Intheflowcharts,eachnumberedboxshowstheprogramminglogicforoneinstruction.Followtheflowchartasyoureadthenumberedsteps.

Step①Thefirstinstructionestablishesthememorylocationwherethedatafilewillstart.Atthestartoftheprogram,youusealoadregisterimmediateinstructiontoloadtheregisterpairwiththefile’sstartingaddress.

Step②Wearenowreadytoloadtheaccumulator.ThesecondinstructioninputsdatafromtheI/Oportandplacesitintheaccumulator.TheinputinstructionbringsdatafromI/Oport01.

Step③Thisinstructionusesastoreinstructionwithanindirectaddress.Itstorestheaccumulator’sdatainthememorylocationpointedtobytheregisterpair.Note:Youdonotstorethedataintheregisterpair.Rather,thedataisstoredinthememorylocationpointedtobytheregisterpair.Youareusingregisterindirectaddressing.Oncethedataisstored,theprogramgetsanotherbyteofdataandstoresitinthenextmemorylocation.

Step④Tomaketheregisterpairpointtothenextmemorylocation,theregisterpairisincrementedbyonecount.

Step⑤Oncetheregisterpairisincremented,itpointstothememorylocationwherethenextbyteofdataistobestored.Youmaynowrepeattheinputandstoreinstructions.Ajumpinstructionreturnsyoutotheinputinstruction.Youjumpbacktotheinstructionthatfollowstheloadregisterpairimmediateinstruction.Youdothisbecauseyoudonotwanttoreloadtheregisterpair.Ifyouwentthroughtheloadprocess,youwoulddestroytheincrementedmemorypointerandkeeploadingdatainthesamememorylocation.Figure3.9Aprogramtoloaddataintosequentialmemorylocationsusingregisterindirectaddressing

3. Registerrelativeaddressing

LikeMOVAX,1234H[SI],relativeaddressingismuchlikeindexedaddressing,buttherearesomedifferences.First,theinstruction’soffsetisaddedtoadifferentregisterineachoftheseaddressingmodes.Inrelativeaddressing,theoffsetisrelativetotheprogramcounter’scurrentvalue.Second,relativeaddressingusuallyusesaspecialformofradixcomplementarithmetic.Theuseofthisspecialarithmeticmakespossiblebranchingforwardwhentheoffsethasalogic0inthemostsignificantbit.Thespecialarithmeticalsopermitsbranchingbackwardwhentheoffsethasalogic1inthemostsignificantbit.Theoffsetisthentreatedasaradixcomplementnumber.

[ReadingMaterial]Whydowesometimesuserelativeaddressinginsteadofindexedaddressing?Forsomemicroprocessors,relativeaddressingistheonlymodeprovideforsomeinstructions.Often,theconditionalbranchinstructionusesonlyrelativeaddressing.Furthermore,relativeaddressingpermitswritingposition-independentcode.Position-independentcodeisalsocalledrelocatableorrelativecode.

Theaddressingofprogrammingcodeiswrittenrelativetothedatainthemicroprocessor’sprogramcounter.Consequently,thesamecodecanbeusedatanymemorylocation.Figure3.10showsaflowchartforaroutinethatmaybecodedineitherabsoluteorrelativecode.Absolutecodemeansthatthecodemustbeusedatafixedsetofmemorylocations.Table3.2(a)showsabsolutecode,theTable3.2(b)showsrelativecode.Figure3.10Aflowchartofaprogramtotestaninputport’sstatusregister toseeifthedataavailableisset

Thissubroutineinputsdatafromastatusregister.TheANDimmediateinstructionmasksallbutthedataavailableflaginthestatusregister(statusregisterbit1).Ifthebitissettologic1,theaccumulatorwillnotbe0aftertheANDinstructionexecutes.Thismeansnojumptakesplace.ThenextinstructioninputsadatawordfromI/Oport01H.

Ifthestatusregisterbitisnotset,alltheaccumulatorbitsarelogic0.Ajumpoccurs.Hereiswherethetwoprogramsdiffer.TheprograminTable3.2(a)jumpsbacktomemorylocation0000H.However,theprograminTable3.2(b)usesrelativeaddressing.Itjumpsbacksixmemorylocationsformtheprogramcounter’scurrentvalue.Remember,theprogramcounterispointingtothein(next)instruction,whilethejumpinstructionisexecuting.

Thejumpinstructiontellsthemicroprocessortojumpbackbyasmanystepsastheradixcomplementofthenumberintheinstruction’ssecondbyte.Inthiscase,thebackwardjumpissixlocationsbecauseFAHistheradixcomplementof6.TheinstructionJZRFAreallyjustsays,“Subtract6fromthecontentsoftheprogramcounter.”Hereisthesubtraction:

Table3.3showstheprogramfromTable3.2(b).Here,theprogramstartsatmemorylocation01AEH.Noneoftheinstructionmnemonicsinthelistingnoranyoftheaddressesaredifferent.Jumpingbacksixlocationsrelativetotheprogramcounter,eventhoughtheprogramcounternowpointstomemorylocation01B4H,stilltakesyoubacktotheinputstatusregisterinstruction(nowatmemorylocation01AEH).

Asyouhaveseen,relativeaddressingfreestheprogrammerfromworryingaboutwheretheprogram’sabsoluteaddressis.Buttheprogrammermustbegoodathexadecimalarithmetictocomputetherelativeaddresses.Usinganassemblerrelievestheprogrammeroftheneedtocalculaterelativeaddresses.Theassemblerdoesallthecalculationsitself.

4. Basedindexedaddressing

Combiningthebasedaddressingmodeandtheindexedaddressingmoderesultsinanew,morepowerfulmodeknownasbased-indexedaddressingmode.Letusconsideranexampleofamoveinstructionusingthistypeofaddressing.

MOVAH,[BX][SI]

Notethatthesourceoperandisaccessedusingbased-indexedaddressingmode.Therefore,theeffectiveaddressofthesourceoperandisobtainedas

EA=(BX)+(SI)

AndthephysicaladdressoftheoperandiscomputedfromthecurrentsofDSandthecalculatedEA.

PA=DS:(BX)+(SI)

Figure3.11(a)and(b)presentanexampleofexecutingthisinstruction.Usingthecontentsofthevariousregistersintheexample,theaddressofthesourceoperandiscalculatedas

PA=0200016+100016+200016=0500016

ExecutionoftheinstructioncausesthevaluestoredatthislocationinmemorytobereadintoAH.Figure3.11(a) Instructionusingbased-indexedaddressingmodebeforefetchandexecution;(b) Afterexecution

4Thisaddressingmodecanbeusedtoaccesscomplexdatastructuressuchastwo-dimensionalarrays.Figure3.12(a)showshowitcanbeusedtoaccesselementsinanm×narrayofdata.Noticethatthedisplacement,whichisafixedvalue,locatesthearrayinmemory.Thebaseregisterspecifiesthemcoordinateofthearray,andtheindexregisteridentifiesthencoordinate.Simplychangingthevaluesinthebaseandindexregisterspermitsaccesstoanyelementinthearray.Figure3.12(b)showstheregisterpermittedinthebased-indexedphysicaladdresscomputation.Figure3.12(a)Based-indexedaddressingofatwo-dimensionalarrayofdata;

(b)Specificationofabased-indexedaddress

5. Relativebasedindexedaddressing

Thisaddressingmodecombinesallofthefeaturesoftheaddressingmodeswehavebeenexamining.Aswithalltheothers,itstillcanaccessmemorylocationsonlywithinone64KBsegment.Itdoes,however,givetheprogrammertheoptionofusing

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论