AND指令可用于复位某些位(同0相与)_第1页
AND指令可用于复位某些位(同0相与)_第2页
AND指令可用于复位某些位(同0相与)_第3页
AND指令可用于复位某些位(同0相与)_第4页
AND指令可用于复位某些位(同0相与)_第5页
已阅读5页,还剩33页未读 继续免费阅读

下载本文档

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

文档简介

Chapter8BitManipulationContents:LogicalOperationsShiftandRotateInstructions8.1LogicalOperationsANDdestination,sourceTESTdestination,sourceThesameasANDinstructionbutnotchangedestinationNOTdestinationORdestination,sourceinclusiveXORdestination,sourceexclusiveTruetableABT000010100111ANDsrcregmemimmreg√√√mem√√destABT000011101110ABT000011101111AT0110flagsLogicaloperationexceptforNOTwillaffectflagregister.CF=0OF=0AF:undefinedPF,SF,ZF:setbythevalueofresult.Clearselectedbits(marking)ClearallbutthelastfourbitsinEAXANDeax,0000000fhSetselectedbitsSetallbutthelastfourbitsinEAXOReax,fffffff0hnegateselectedbitsnegateallbutthelastfourbitsinEAXXOReax,fffffff0hXoreax,eax;AND指令可用于复位某些位(同0相与),不影响其他位:将BL中D3和D0位清0,其他位不变and

bl,11110110B;OR指令可用于置位某些位(同1相或),不影响其他位:将BL中D3和D0位置1,其他位不变or

bl,00001001B;XOR指令可用于求反某些位(同1相异或),不影响其他位:将BL中D3和D0位求反,其他不变xor

bl,00001001BPerformcertainarithmeticoperationmovedx,0movebx,32divebxmovedx,eaxandedx,0000001fhManipulateASCIIcodesConvertASCIIcodetointegerSubeax,00000030hAndeax,0000000fhConvertintegertoASCIIOrbl,30hChangethecaseofASCIIcodeXorcl,00100000bApplicationofTESTExamineaparticularbitis“1”or“0”Testdx,2023hGetinformationaboutavalueTestcx,cxThefollowinginstructionusuallyis“jcc”testal,01h

;测试AL旳最低位D0jnzthere ;标志ZF=0,即D0=1 ;则程序转移到there... ;不然ZF=1,即D0=0,顺序执行there:...

TEST指令一般用于检测某些条件是否满足,但又不希望变化原操作数旳情况TESTShiftandRotateShiftandrotateinstructionsmanipulatebinarynumbersatthebinarybitlevel,asdidtheAND,OR,Exclusive-OR,andNOTinstructions.Shiftsandrotatesfindtheirmostcommonapplicationsinlow-levelsoftwareusedtocontrolI/Odevices.Themicroprocessorcontainsacompletesetofshiftandrotateinstructionsthatareusedtoshiftorrotateanymemorydataorregister.ShiftinstructionsShiftinstructionspositionormovenumberstotheleftorrightwithinaregisterormemorylocation.LogicalshiftArithmeticshiftLogicalshifts

multiplyordivide

unsigneddata,andarithmeticshiftsmultiplyordividesigneddata.Ashiftleftmultipliesby2foreachbitpositionshiftedashiftrightdividesby2foreachbitpositionshiftedShiftinstructions

SHLdest,count SHRdest,count SALdest,count SARdest,count ;destisthetargetoperandbeingshiftedusingregisterormemoryaddressingmode ;countisthenumberoftimes(orbits)thattheoperandisshifted,itcanbespecifieddirectlyusinganimmediateshiftcount,orthroughtheCLregister.SHL/SALinstructionSHRinstructionSARinstructionflagsShiftinstructionswillchangeflags:CF:changebyshiftedbitOF:Multiple-bitshift:undefinedSingle-bitshift0:ifthesignbitoftheresultisthesameasthesignbitoftheoriginaloperandvalue.1:theyaredifferentZF,PF:assignedaccordingtoresultAF:undesignedExamplessalcx,1;beforecx=a9d7shrax,1;beforeax=a9d7sarbx,1;beforebx=a9d7salace,4;beforeace=a9d7shrdx,4;beforedx=a9d7sarax,cl;beforeax=a9d7,cl=04;将DX.AX中32位数值左移一位shlax,1rcldx,1DXAXCF0;把AL最低位送BL最低位,保持AL不变rorbl,1roral,1rclbl,1rolal,1AL、BLCFBLCFALCFAL之D0Figure8.7…leaebx,hexOut+7movecx,8forCount:movedx,eaxandedx,0000000fhcmpedx,9jnleelseLetteroredx,30h

jmpendifDigitelseLetter:addedx,‘A’-10EndifDigit:movBYTEPTR[ebx],dlDecebxshreax,4LoopforCount…Doubleshiftinstructionssh-ddest,src,count-:l(leftshift),r(rightshift)dest:wordordoublewordinaregisterormemorysrc:wordordoublewordinaregistercount:immediateorCLflagsCF:lastbitshiftedoutgoestoCFSF,ZF,PF:assignedcorrespondingtotheresultOF:undefinedExamples:shldecx,eax,12;beforeECX=12345678,EAX=90ABCDEFshrdecx,eax,CL;beforeECX=12345678,EAX=90ABCDEF,CL=08Figure8.7…

leaebx,hexOut

;leaebx,hexOut+7movecx,8forCount:shldedx,eax,4

;movedx,eaxandedx,0000000fhcmpedx,9jnleelseLetteroredx,30hjmpendifDigitelseLetter:addedx,‘A’-10EndifDigit:movBYTEPTR[ebx],dl

incebx

;decebx

shleax,4

;shreax,4loopforCount…Rotateinstructions

rotatedest,count ;rotateisRCL(rotateleftwithcarry),RCR(rotaterightwithcarry),ROL(rotateleft),andROR(rotateright) ;destisthetargetoperandbeingrotatedusingregisterormemoryaddressingmode ;countisthenumberoftimes(orbits)thattheoperandisrotated,itcanbespecifieddirectlyusinganimmediateshiftcount,orthroughtheCLregister.RotateoperationRotateinstructionspositionbinarydatabyrotatingtheinformationinaregisterormemorylocation,eitherfromoneendtoanotherorthroughthecarryflag.Rotateinstructionsareoftenusedtowidenumberstotheleftorright.ROLinstructionRORinstructionRCLinstructionRCRinstruction;将DX.AX中32位数值左移一位shlax,1rcldx,1DXAXCF0;把AL最低位送BL最低位,保持AL不变rorbl,1roral,1rclbl,1rolal,1AL、BLCFBLCFALCFAL之D0Figure8.7…

leaebx,hexOut+7

;leaebx,hexOutmovecx,8forCount:roleax,4

movedx,eaxandedx,0000000fhcmpedx,9jnleelseLetteroredx,30hjmpendifDigitelseLetter:addedx,‘A’-10EndifDigit:movBYTEPTR[ebx],dl

incebx

;decebx

;shreax,4loopforCount…ASCIItodoubleintegerconversionAtodprocedureatodprocPROCNEAR32pushebp;savebasepointermovebp,esp;establishstackframesubesp,4;localspaceforsignpushebx;Saveregisterspushecxpushedxpushf;saveflagsmovesi,[ebp+8];getparameter(sourceaddr)WhileBlankD:cmpBYTEPTR[esi],'';space?jneEndWhileBlankD;exitifnotincesi;incrementcharacterpointerjmpWhileBlankD;andtryagainEndWhileBlankD:moveax,1;defaultsignmultiplierIfPlusD:cmpBYTEPTR[esi],'+';leading+?jeSkipSignD;ifso,skipoverIfMinusD:cmpBYTEPTR[esi],'-';leading-?jneEndIfSignD;ifnot,savedefault+moveax,-1;-1forminussignSkipSignD:incesi;movepastsignEndIfSignD:mov[ebp-4],eax;savesignmultipliermoveax,0;numberbeingaccumulatedmovcx,0;countofdigitssofarWhileDigitD:cmpBYTEPTR[esi],'0';comparenextcharacterto'0'jlEndWhileDigitD;notadigitifsmallerthan'0'cmpBYTEPTR[esi],'9';compareto'9'jgEndWhileDigitD;notadigitifbiggerthan'9'imuleax,10;multiplyoldnumberby10jooverflowD;exitifproducttoolargemovbl,[esi];ASCIIcharactertoBLandebx,0000000Fh;converttosingle-digitintegeraddeax,ebx;addtosumjcoverflowD;exitifsumtoolargeinccx;incrementdigitcountincesi;incrementcharacterpointerjmpWhileDigitD;gotrynextcharacterEndWhileDigitD:cmpcx,0;nodigits?jzoverflowD;ifso,setoverflowerrorflag;ifvalueis80000000handsignis'-',;wanttoreturn80000000h(-2^32)cmpeax,80000000h;80000000h?jneTooBigD?cmpDWORDPTR[ebp-4],-1;multiplier-1?jeok1D;ifso,return8000hTooBigD?:testeax,eax;checksignflag

温馨提示

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

最新文档

评论

0/150

提交评论