微机系统与接口ch4new_第1页
微机系统与接口ch4new_第2页
微机系统与接口ch4new_第3页
微机系统与接口ch4new_第4页
微机系统与接口ch4new_第5页
已阅读5页,还剩67页未读 继续免费阅读

下载本文档

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

文档简介

Chapter4:DataMovementInstructionsIntroduction

Thischapterconcentratesonthedatamovementinstructions.ThedatamovementinstructionsincludeMOV,PUSH,POP,XCHG,XLAT,IN,OUT,LEA,LDS,LES,LAHF,SAHF.Stringinstructions:MOVS,LODS,STOS,Contents

4–1MOVRevisited4–2PUSH/POP4–3Load-EffectiveAddress4–4StringDataTransfers4–5MiscellaneousDataTransferInstructions4–1

MOVRevisitedMicrosoftMACROassembler(MASM)Intel

Assembler(ASM)BorlandTurboassembler(TASM)COPYMOVdst,src ;(dst)←(src)Dst:R,M,SR;Src:R,M,SR,ImRegImSRMMOVDX,BP ;MOVAX,ES ;MOVSP,1800H ;MOVBL,[2480H] ;MOVDS,[BX+DI] ;MOVBYTEPTR[SI],0FH ;4–1

MOVRevisited4–2

PUSH/POPImportantinstructionsthatstoreandretrievedatafromtheLIFO(last-in,first-out)stackmemory.SixformsofthePUSHandPOPinstructions:register,memory,immediatesegmentregister,flags,allregistersImmediateaddressingallowsimmediatedatatobepushedontothestack,butnotpoppedoffthestack.4–2

PUSH/POP71、PUSHPUSHCX ;regPUSHDS ;segPUSH[0040H]

;memSP-22、POPPOPSI ;regPOPES ;segPOP[BX] ;memSP+2CS,No!第2节8086/8088指令系统4–2

PUSH/POPSegmentregisterCSmaybepushed,butdatafromthestackmayneverbepoppedintoCSTheflagsmaybepushedorpoppedfrom

thatstack.contentsofallregistersmaybepushedor

poppedAlwaystransfers2bytesofdatatothestack;PUSHF(pushflags)instructioncopiesthecontentsoftheflagregistertothestack.PUSHSS=3200H,SP=0800H,AX=105CH。SP=0800H→32800H……StackPUSHAXSP=SP-1→327FFHSP=SP-1→327FEHSP=07FEH5CHAL10HAHPUSHFigure4–13

TheeffectofthePUSHAXinstructiononESPandstackmemorylocations37FFHand37FEH.Thisinstructionisshownatthepointafterexecution.

PUSHPUSHCX ;RPUSHDS ;SRPUSH[0040H];MPOPPerformstheinverseoperationofPUSH.POPremovesdatafromthestackandplacesitinatarget16-bitregister,segmentregister,ora16-bitmemorylocation.notavailableasanimmediatePOP POPF(popflags)removesa16-bitnumberfromthestackandplacesitintheflagregister;SS=3200H,SP=07FEHSP=SP+1→32800HPOPAXSP=SP+1→327FFHSP=07FEH→327FEH……Stack10H5CHSP=0800HAX=105CHAHALLIFOPOPFigure4–15

ThePOPBXinstruction,showinghowdataareremovedfromthestack.Thisinstructionisshownafterexecution.

POPPOPSI ;RPOPES ;SRPOP[BX] ;M4–3

LOADEFFECTIVEADDRESSLEAinstructionloadsany16-or32-bitregisterwiththeoffsetaddressLDSandLESloada16-bitregisterwithoffsetaddressretrievedfromamemorylocationthenloadeitherDSorESwithasegment

addressretrievedfrommemory4–3

LOADEFFECTIVEADDRESSLEA16-bitR,MLDS16-bitR,MLES16-bitR,MLEALoadsa16-bitregisterwiththeoffsetaddressofthedataspecifiedbytheoperand.LEA;MOVwithOFFSET

LEABX,[DI]MOVBX,OFFSET[DI]LDS,LESLoadany16-or32-bitregisterwithanoffset

address,andtheDS,ES,segmentregisterwithasegmentaddress.instructionsuseanymemory-addressingmodes

toaccessa32-bitmemorysectionthatcontainbothsegmentandoffsetaddressFigure4–17

TheLDSBX,[DI]instructionloadsregisterBXfromaddresses11000Hand11001HandregisterDSfromlocations11002Hand11003H.ThisinstructionisshownatthepointjustbeforeDSchangesto3000HandBXchangesto127AH.

LDS,LESThisinstructiontransfersthe32-bitnumber,addressedbyDIinthedatasegment,into

theBXandDSregisters.LDS,LESinstructionsobtainanewfaraddressfrommemory.offsetaddressappearsfirst,followedbythesegmentaddress Thisformatisusedforstoringall32-bitmemoryaddresses.LDS,LES4–4

STRINGDATATRANSFERSSTRING?Fivestringdatatransferinstructions:LODS,STOS,MOVS.Eachallowsdatatransfersasasinglebyte,word,ordoubleword.Beforethestringinstructionsarepresented,theoperationoftheDflag-bit(direction),DI,andSImustbeunderstoodastheyapplytothestringinstructions.4–4

STRINGDATATRANSFERSTheDirectionFlagThedirectionflag(D,locatedintheflagregister)selectstheauto-incrementortheauto-decrementoperationfortheDIandSIregistersduringstringoperations.usedonlywiththestringinstructionsTheCLDinstructionclearstheDflagandtheSTDinstructionsetsit.CLD(DF=0)instructionselectstheauto-incrementmodeandSTD(DF=1)selectstheauto-decrementmodeDIandSIDuringexecutionofstringinstruction,memoryaccessesoccurthroughDIandSIregisters.DIoffsetaddressaccessesdataintheextrasegmentforallstringinstructionsthatuseitSIoffsetaddressaccessesdatabydefault

inthedatasegment

DS:SI——Source;changedbyasegmentoverrideprefixES:DI——Target;neverchangedLODSSOURCELABELLODSB:AL←(DS:SI),SI←SI±1LODSW:AX←(DS:SI)

,SI←SI±2LODSLODSLoadsAL,AXwithdataatsegmentoffsetaddressindexedbytheSIregister.Figure4–18

TheoperationoftheLODSWinstructionifDS=1000H,D=0,11000H,11001H=A0.ThisinstructionisshownafterAXisloadedfrommemory,butbefore

SIincrementsby2.

STOSStoresAL,AX

attheextrasegmentmemorylocationaddressedbytheDIregister.STOSB(storesabyte)storesthebyteinALattheextrasegmentmemorylocationaddressedbyDI.STOSW(storesaword)storesAXinthememorylocationaddressedbyDI.Afterthebyte(AL),word(AX)isstored,contentsofDIincrementordecrement.

STOSTARGETLABEL

STOSB:(ES:DI)←AL,DI←DI±1STOSW:(ES:DI)←AX,DI←DI±2STOSREPNZ/REPNESTRINSTRUCTIONRepeatwhileNotEqual/NotZero),UNTILLZF=1

ORCX=0REP/REPNZ/REPNESTOSwithaREP

Therepeatprefix(REP)isaddedtoanystringdatatransferinstructionexceptLODS.REPSTOSREPprefixcausesCXtodecrementby1eachtimethestringinstructionexecutes;afterCXdecrements,thestringinstructionrepeatsIfCXreachesavalueof0,theinstructionterminatesandtheprogramcontinues.IfCXisloadedwith100andaREPSTOSBinstructionexecutes,themicroprocessorautomaticallyrepeatstheSTOSB100times.27UppercasetoLowercase,thenstoreinthetarget:

MOVCX,40 ;count

LEASI,STR1 ;SI,source(DS)

LEADI,STR2 ;DI,target(ES)

CLD

;DF=0,IncreaseAGN: LODSB ;toAL

ADD AL,‘a’-‘A’

;→

STOSB ;store

LOOPAGN ;loop

……MOVSTransfersabyte,wordadatasegmentaddressedbySItoextrasegmentlocationaddressedbyDI.Thedestinationoperand(DI)mustalwaysbelocatedintheextrasegment.MOVSB,MOVSWREPMOVS

;transferuntilCX=0MOVSDI,SIMOVSB;(ES:DI)←(DS:SI),SI←SI±1,DI←DI±1MOVSW;(ES:DI)←(DS:SI),SI←SI±2,DI←DI±2MemorySOURCETARGETMemoryCOURCETARGETMOVSMOVCX,10H ;COUNTLEA SI,STR1 ;STR1:SOUCEADDSI,30

;ENDOFSTR1LEADI,STR2 ;STR2:TARGETADDDI,30

;ENDOFTARGETSTD ;DF=1,DECREACEREPMOVSW ;16WORDSTRANSFERMOV?WORD-STRINGTRANSFER:MOVS4–5

MISCELLANEOUSDATATRANSFERINSTRUCTIONSXCHG,LAHF,SAHF,XLAT,IN,OUTXCHGExchangescontentsofaregisterwithanyotherregisterormemorylocation.cannotexchangesegmentregistersXCHGop1,op2;(op1)

(op2)op1:R,M;op2:R,MREGMEMLAHFandSAHFLAHFinstructiontransferstherightmost8bitsoftheflagregisterintotheAHregister.SAHFinstructiontransferstheAHregisterintotherightmost8bitsoftheflagregister.34LAHF(Flags)L→AHSAHFAH→(Flags)LPUSHF

POPF

Hidden唯一可改变TF的指令!第2节8086/8088指令系统TF

1POPF ;(SS:SP)→FlagsPUSHF ;Flags→(SS:SP)MOVBP,SPMOV[BP+1],01HOR[BP+1],01H;←BPSS:0000HSP→(Flags)L(Flags)H←BP+101H————ODITSZ—A—P—C1514131211109876543210Flags:(Flags)H(Flags)LXLATConvertsthecontentsoftheALregisterintoanumberstoredinamemorytable.performsthedirecttablelookuptechniqueoftenusedtoconvertonecodetoanotherAnXLATinstructionfirstaddsthecontentsofALtoBXtoformamemoryaddresswithinthedatasegment.copiesthecontentsofthisaddressintoALonlyinstructionaddingan8-bittoa16-bitnumberFigure4–19

TheoperationoftheXLATinstructionatthepointjustbefore6DHisloadedintoAL.

XLAT38TABDB0,1,4,9,16,25,36,49,64,81;……MOVBX,OFFSETTABMOVAL,4XLATTABAL=16。XLATINandOUTIN&OUTinstructionsperformI/OoperationsContentsofAL,AXaretransferredonlybetweenI/Odeviceandmicroprocessor.anINinstructiontransfersdatafromanexternalI/OdeviceintoAL,AXanOUTtransfersdatafromAL,AXtoanexternalI/OdeviceTwoformsofI/Odevice(port)addressing:Fixed-portaddressingallowsdatatransferbetweenAL,AXusingan8-bitI/Oportaddress.(portnumber)Variable-portaddressingallowsdatatransfersbetweenAL,AX,anda16-bitportaddress.theI/OportnumberisstoredinregisterDX,

INandOUTFigure4–20

Thesignalsfoundinthemicroprocessor-basedsystemforanOUT19H,AXinstruction.

INandOUT4–6

SEGMENTOVERRIDEPREFIXMaybeaddedtoalmostanyinstructioninanymemory-addressingmodeallowstheprogrammertodeviatefromthe

defaultsegmentonlyinstructionsthatcannotbeprefixedarejumpandcallinstructionsusingthecodesegmentregisterforaddressgenerationAdditionalbyteappendedtothefrontofaninstructiontoselectalternatesegmentregisterMOVAL,[DI];DS:[DI]MOVAL,ES:[DI]4–6

SEGMENTOVERRIDEPREFIX4–7

ASSEMBLERDETAILTheassemblercanbeusedtwoways:withmodelsuniquetoaparticularassemblerwithfull-segmentdefinitionsthatallowcompletecontrolovertheassemblyprocessandareuniversaltoallassemblersDirectivesTheDB(definebyte)directivestoresbytesofdatainthememory.BYTEPTRindicatesthesizeofthedatareferencedbyapointerorindexregister.ComplexsectionsofassemblycodearestillwrittenusingMASM.StoringDatainaMemorySegment

DB(definebyte),DW(defineword),andDD(definedoubleword)aremostoftenusedwithMASMtodefineandstorememorydata.Ifanumericcoprocessorexecutessoftwareinthesystem,theDQ(definequadword)andDT(definetenbytes)directivesarealsocommon.Thesedirectiveslabelamemorylocationwithasymbolicnameandindicateitssize.

DA1DB10H,52HDA2DW1122H,34HDA3DD5*20H,0FFEEH

StoringDatainaMemorySegment

FIRSTDB‘HELLO’;SECONDDW‘OK’;StoringDatainaMemorySegment

M1DB?

;M2DW0D55H,?

;ONEDB5DUP(0)TWODW10DUP(?)THREEDB4DUP(1,2DUP(20H))THREE:howmanybytes?THREE-ONE=????StoringDatainaMemorySegment

OPE1DB1,2OPE2DW2233H,5566H

MOVAX,OPE1+1;????MOVAL,OPE2;???????

MOVAX,WORDPTROPE1+1;

MOVAL,BYTEPTROPE2;AX=3302HAL=33HStoringDatainaMemorySegment

ASSUME,EQU,andORG

Equatedirective(EQU)equatesanumeric,ASCII,orlabeltoanotherlabel.equatesmakeaprogramclearerandsimplifydebuggingTheTHISdirectivealwaysappearsasTHISBYTE,THISWORD,THISDWORD,orTHISQWORD.Theassemblercanonlyassigneitherabyte,word,ordoublewordaddresstoalabel.

COUNTEQU100;DATAEQUCOUNT+2;A1EQU[DX+SI];B1EQUOFFSETA1;C1EQUADD;COUNT=100COUNT=COUNT+10A1=BX+SIMOVAX,[A1];B1=ADDA1=BXMOVCX,[A1]ASSUME,EQU,andORG

ASSUMEASAUMECS:cseg_name,DS:dseg_name,SS:sseg_name,ES:eseg_nameASSUME,EQU,andORG

Proc_namePROC属性;

……;

RET[N]Proc_nameENDPPROCandENDP

ThePROCdirective,whichindicatesthestartofaprocedure,mustalsobefollowedwithaNEARorFAR.

ANEARprocedureisonethatresidesinthesamecodesegmentastheprogram,oftenconsideredtobelocal

AFARproceduremayresideatanylocationinthememorysystem,consideredglobal

PROCandENDP

SEGMENT/ENDSseg_name

SEGMENT ……….seg_name

ENDSFull-SegmentDefinitionsMYDATA SEGMENT X DB ? Y DW ? Z DD ?MYDATA ENDSMYEXTRA SEGMENT ALPHA DB ? BETA DW ? GAMMA DD ?MYEXTRA ENDSMYSTACK SEGMENT DW 100DUP(?) TOP EQU THIS WORDMYSTACK ENDSFull-SegmentDefinitions my_codesegment

assumecs:my_code,ds:my_data,ss:ss_seg mainprocfar ……Full-SegmentDefinitionsMYCODE SEGMENTASSUMECS:MYCODE,DS:MYDATA,ES:MYEXTRA,SS:MYSTACKSTART: MOV AX,MYDATA ; 或MOV AX,SEGX MOV DS,AX MOV AX,MYEXTRA ;或MOVAX,SEGALPHA MOV ES,AX MOV AX,MYSTACK ; MOV SS,AX MOV SP,OFFSETTOP ………………MYCODE ENDS END STARTFull-SegmentDefinitionsDATA SEGMENT ;D1 DB5DUP(?) ;CC EQU$-D1 ;SUM DW0 ;DATA ENDS ;STACKSEGMENTPARASTACK‘STACK’

;

DB100DUP(?)

;STACK ENDS

;CODE SEGMENT

;

ASSUMEDS:DATA,SS:STACK,CS:CODE;BEGIN:MOVAX,DATA ;

MOVDS,AX LEASI,D1 ;定义存储单元的数据伪指令定义堆栈段定义语句指令

MOVCX,CC+1 ;预置次数

LODSBYTEPTR[SI] ;取一个数并修改指针

DECCX ;修改次数

MOVAH,0 ;清AX的高字节

CLC ;清CF位AGAN:ADCSUM,AX ;累加

LODSBYTEPTR[SI] ;再取数并修改指针

LOOPAGAN ;控制循环

MOVAH,4CH ;完成,返回DOS INT21HCODE ENDS

;代码段结束

END BEGIN ;整个程序结束段定义汇编程序结束SUMMARYDatamovementinstructionstransferdatabetweenregisters,aregisterandmem-ory,aregisterandthestack,memoryandthestack,theaccumulatorandI/O,andtheflagsandthestack.Memory-to-memorytransfersareallowedonlywiththeMOVSinstruction.SUMMARYDatamovementinstructionsincludeMOV,PUSH,POP,XCHG,XLAT,IN,OUT,LEA,LDS,LES,LAHF,SAHF,andthefollowingstringinstruc-tions:LODS,STOS,MOVS.Thefirstbyteofaninstructioncontainstheopcode,whichspecifiestheoperationperformedbythemicroprocessor.Theopcodemaybeprecededbyoneormoreoverrideprefixes.(cont.)SUMMARYLEA,LDS,andLESinstructionsloadaregisterorregisterswithaneffectivead-dress.TheLEAinstructionloadsany16-bitregisterwithaneffectiveaddress;LDSandLESloadany16-bitregisterandeitherDSorESwiththeeffectiveaddress.(cont.)SUMMARYThedirectionflag(D)choosestheauto-incrementorauto-decrementmodeofop-erationforDIandSIforstringinstructions.ToclearDto0,usetheCLDinstructiontoselecttheauto-incrementmode;tosetDto1,usetheSTDinstructiontoselect

温馨提示

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

评论

0/150

提交评论