您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > 07-chapter6
Chapter6ProgramControl&StringProcessingInstructionsProgramControlInstructionsStringOperationProceduresInterruptsProgramControlInstructionsInstructionLabelsAlabelstandsfortheaddressofthefirstbyteoftheinstruction,thepurposeofwhichistogiveamarkforthetransferinstructions.Thelabelisterminatedbyacolon,whichgivesitthenearattribute:thatis,thelabelisinsideaprocedureinthesamecodesegment.标号的属性:段、段内偏移地址、类型(标号可转移的距离,near或far等)。标号命名规则:以字母或下划线开头,后跟字母、数字、下划线,长度不超过31个字符。系统保留字不能作为标号(如指令的操作码助记符、运算符、寄存器名、伪指令助记符等)。JMPTheJMPinstructionisaGOTOthatisfoundinallcomputerlanguages.JMPpassesprogramflowtoanotherpartoftheprogram.TheJMPinstructioncomesin3forms,short,near,andfar.Shortjumpsarewithin+127and-128bytesfromtheJMPinstruction.Nearjumpsarewithin±32K(protectedmodenearjumps±2G.)Farjumpsareanywherewithinthememorysystem.ShortJMPNearJMPFarJMPIndirectJumpsIndirectjumpstaketwoforms.Onejumpstotheoffsetlocationaddressedbyaregisterandtheotherjumpstothelocationaddressedbyamemorypointer.JMPCXJMPEDXJMPNEARPTR[BX]JMPFARPTR[ECX]UnconditionalJMPShortandnearJMP段内直接转移(操作数是位移量)JMPlabelJMPSHORTlabel(-128~+127,1-byte)段内间接转移(操作数是存放有效地址的单元)JMPregister(根据需要使用PTR)JMPmemory(根据需要使用PTR)farJMP段间直接转移JMPlabel(使用PTR)段间间接转移JMPmemory(32位)(使用PTR)高16位→CS,低16位→IP本模块:EXTRN说明标号目标模块:PUBLIC说明标号TheJMPinstructionsJMPSHORTPRO_2JMPNEARPTRPRO_3JMPBXJMPWORDPTR5[BX]JMPFARPTRPRO_4JMPDWORDPTR[DI]DATASEGMENTUSE16…ADDRDD12345678H…DATAENDSCODESEGMENTUSE16…JMPADDR…CODEENDSAnyproblems?例:UsingtheJMPInstructionThisloophasnoexit,processingisendless.ConditionalJumpsTherearemanyconditionaljumpinstructions.Conditionaljumpinstructions,forthemostpart,testtheflagbits.Conditionaljumpscanbeeithershortornear.Inprotectedmodeaconditionaljumpcanhavea32-bitdisplacement.Somecheckasingleflagbit,whilesomecheckmultipleflagbits.Onesetofconditionaljumpstestunsignednumbers(JZ,JNZ,JA,JB,JAE,orJBE).Onesetofconditionaljumpstestsignednumber(JZ,JNZ,JG,JL,JGE,andJLE).Twosetsofconditionaljumpsareneededbecausethenumericorderofsignedandunsignednumbersdiffers.(seenextslide)ConditionalJMP按标志位:有进/借位,跳JCJumponC=1无进/借位,跳JNCJumponC=0结果为零,跳JZJumponZ=1结果不为零,跳JNZJumponZ=0负数,跳JSJumponS=1正数,跳JNSJumponS=0奇偶校验,偶,跳JPJumponP=1奇偶校验,奇,跳JNPJumponP=0溢出,跳JOJumponO=1非溢出,跳JNOJumponO=0无符号数:•被减数减数,跳JAJumpifAbove•被减数=减数,跳JBEJumpifBelow/Equal•被减数=减数,跳JAEJumpifAbove/Equal•被减数减数,跳JBJumpifBelowConditionalJMP有符号数:•被减数减数,跳JGJumpifGreater•被减数=减数,跳JLEJumpifLess/Equal•被减数=减数,跳JGEJumpifGreater/Equal•被减数减数,跳JLJumpifLessConditionalJMPJUMPTABLESTestanumberofrelatedconditions,eachrequiringajumptoanotherroutine.Establishatableofjump.JUMP[CUSTTAB+BX]formsanaddressbasedonthestartofthetableplusanoffsetintothetable.Mustchecktheinputvalue,preventillegalinput.TheLoopinginstructionsCX0,循环LOOP(E)CX=(E)CX-1CX0ANDZ=1,循环LOOPZ/E(E)CX=(E)CX-1CX0ANDZ=0,循环LOOPNZ/NE(E)CX=(E)CX-1(transferrange:-128----+127)RequiresaninitialvalueintheCXregister.Foreachiteration,LOOPautomaticallydeducts1fromtheCX.Thedistancetotheoperandmustbeashortjump,within-128to+127bytes.LOOPE/LOOPZ:Loopwhileequal0orthezeroconditionisset.LOOPNE/LOOPNZ:Loopwhilenotequal0orthezeroconditionisnotset.CLCC0ClearCSTCC1SetCCMCCCComplementC(取反)CLDD0ClearD(清方向标志)STDD1SetD(设置方向标志)CLII0ClearI(清中断标志,禁止响应中断)STII1SetI(设置中断标志,允许响应中断)ESCEscape(换码,实现对协处理器的控制)WAITWait(使CPU处于暂停状态直到外部中断)LOCK(前缀)Lock(执行指令后使引脚LOCK输出有效信号)HLTHalt(使CPU处于暂停状态)NOPNoOperation(空操作,耗费3个时钟周期)外部同步命令:•使CPU与其他协处理器同步工作。•不影响标志位。ProcessorControl与指令时间周期和CPU的时钟频率有关.T=1/频率MOV寄,寄周期数2CALL段内直接19段内间接37+EAEA:直接寻址6寄存器间接5基址/变址7--8基址+变址11--12ExecutingtimeStringOperationFeaturesofstringoperationSpecifyingtherepetitionofaprocessing;AssumingtheES:DIorDS:SIaspairsofregisters;MOVS,STOS,CMPSandSCASneedtheinitiationofES,usuallywiththesameaddressasinDS.DirectionisdeterminedbyDF(DF=0为递增方向,每执行一次操作,SI和DI增加;DF=1为递减方向。设置指令:CLD,STD)INSTRUCTIONIMPLIEDOPRANDSMOVSES:DI,DS:SILODSAL/AX/EAX,DS:SISTOSES:DI,AL/AX/EAXCMPSES:DI,DS:SISCASES:DI,AL/AX/EAXMOVSmovestringREP:前缀助记符,不能单独使用,CPU在执行有重复前缀的串传送指令时,每传送一个元素,就自动完成CX-1操作,直到CX-1=0为止。MOVSBMOVSWMOVSDREPES:DIDS:SICX=timesREPrepeatstringprefixeg.REPMOVSBREPrepeatuntilCX=0REPE/REPZrepeatwhileZF=1相等继续,不等则停oruntilCX=0REPNE/REPNZrepeatwhileZF=0不等继续,相等则停oruntilCX=0思考:继续执行条件是相等还是不相等?停止呢?思考:继续执行条件是相等还是不相等?停止呢?DATASTR1DB25DUP(‘*’)DATASTR2DB25DUP()…CLDMOVCX,25LEADI,DATASTR2LEASI,DATASTR1REPMOVSB…Whereandwhatistheresult?X189•LODSloadstringLODSBLODSWLODSDREPAL/AX/EAXDS:SILODSBisequivalentto:MOVAL,[SI]INC/DECSISI=SI±1/2/4•STOSstorestringSTOSBSTOSWSTOSDREPAL/AX/EAXES:DICX=times•CMPScomparestring:CMPSBCMPSWCMPSDDS:SIES:DICX=timesREPEREPNEIfequal,Z=1•REPE/REPZrepeatwhileZF=1andCX≠0•REPNE/REPNZrepeatwhileZF=0andCX≠0DirectionaccordingtoDCLD---D=0startingaddressSTD---D=1endingaddressDS:SIDS:SI何时继续?何时停止?相等继续不相等停思考怎样知道相比的字符串中:1.全部相同2.全部不同3.如果有不相同的,第一个在何处4.如果有相同的,第一个在何处A:REPECMPS×B:REPNECMPS×A:REPECMPS×B:REPNECMPS×1.REPECMPS×Z=1(CX=0)2.REPNECMPS×Z=0(CX=0)3.REPECMPS×Z=0根据D、SI/DI4.REPNECMPS×Z=1根据D、SI/DI•SCASscanstringSCASBSCASWSCASDAL/AX/EAXES:DICX=timesREPEREPNEIfequal,Z=1•REPE/REPZrepea
本文标题:07-chapter6
链接地址:https://www.777doc.com/doc-3052277 .html