华南理工大学汇编原理课件04.ppt_第1页
华南理工大学汇编原理课件04.ppt_第2页
华南理工大学汇编原理课件04.ppt_第3页
华南理工大学汇编原理课件04.ppt_第4页
华南理工大学汇编原理课件04.ppt_第5页
已阅读5页,还剩109页未读 继续免费阅读

下载本文档

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

文档简介

PartB FundamentalsofAssemblyLanguage Chapter4 SymbolicInstructions基本的符号指令 Textbook 6SymbolicInstructionsandAddressing 8086Symbolicinstructions AlistofthesymbolicinstructionsfortheIntelprocessorfamilyarrangedbycategory DataTransfer数据传送类指令 ArithmeticandLogical算术 逻辑运算类指令 BitShifting位操作类指令 StringOperation串操作类指令 Transfer ConditionalandUnconditional 控制转移类指令 ProcessorControl处理机控制类指令 Overview FormatoftheInstructions Statementelement identifier mnemonic operand s comment 标识符 助记符 操作数 注释 Instructionswithoutanoperand Eg 1 NOP 空操作指令 HLT 停机指令 2 RET 子程序返回指令 MOVSW 串传送指令 DAA 加法的十进制调整指令 Instructionswithoneoperand 1 withadestinationoperandINCBXDECCX2 withasourceoperandPUSHAXPOPDX Instructionswithtwooperands destinationoperand operand1 sourceoperand operand2 Examples Note FunctionsAddressingmodeAffectFlagregister CopyingDatamovxchg复制数据指令 4 1 MOVinstruction move TheMOVinstructiontransfers orcopies datareferencedbytheaddressinthesecondoperandtotheaddressinthefirstoperand Format 从源操作数地址把一个字节 字或双字复制到目的操作数地址 存放在源地址的值不会改变 比如C语言中赋值语句intcount 0 label MOVreg mem reg mem imm reg mem reg mem imm MOVinstruction move Youcanmovetoaregisterabyte aword oradoubleword ALBLCLDLAHBHCHDHAXBXCXDXSPBPSIDIEAXEBXECXEDXESPEBPESIEDI label MOVreg mem reg mem imm reg mem reg mem imm ValidMOVOperations Byteflddb DefineabyteWordflddb Defineaword1 RegisterMovesmovedx ecx register to registermoves ax register to segmentregistermovbytefld dh Register to memory directmov bx al register to memory indirect Examples ValidMOVOperations Byteflddb DefineabyteWordflddb Defineaword2 ImmediateMovesmovcx 40h immediate to registermovbytefld 25 immediate to memory directmovwordfld bx 25 immediate to memory indirect Examples ValidMOVOperations Byteflddb DefineabyteWordflddb Defineaword3 DirectMomoryMovesmovch bytefld memory to registermovcx wordfld bx memory to register indirect Examples ValidMOVOperations Byteflddb DefineabyteWordflddb Defineaword4 SegmentRegisterMovesmovax ds segmentregister to registermovwordfld ds segmentregister to memory Examples InvalidMOV InvalidMov Memory to memoryImmediate to segmentregisterSegmentregister to segmentregisterDestinationoperandnot sCSorimmediate 注意 源和目的操作数不可以任意组合 MOVinstruction MOVinstructionnotaffectflag Theoperandaffectsonlytheportionofthereferencedregister MovingabytetotheCHdoesnotaffecttheCL imm reg memmov指令 moval 4 al 4 字节传送movcx 0ffh cx 00ffh 字传送movsi 200h si 0200h 字传送movbyteptr si 0ah byteptr说明是字节操作movwordptr si 2 0bh wordptr说明是字操作 注意立即数是字节还是字明确指令是字节操作还是字操作 Examples Mem reg moval bx movdx bp dx ss bp moves si es ds si 不存在存储器向存储器的传送指令 Examples Segreg reg mem mov si dsmovax es ax esmovds ax ds ax es 对段寄存器的操作有一些限制 Examples Summary MOV并非任意传送 不改变状态标志位 非法传送种种 两个操作数的类型不一致例如源操作数是字节 而目的操作数是字 或相反两个操作数不能都是存储器传送指令很灵活 但主存之间的直接传送却不允许段寄存器的操作有一些限制段寄存器属专用寄存器 对他们的操作能力有限 两个操作数的类型要一致 绝大多数双操作数指令 除非特别说明 目的操作数与源操作数必须类型一致 否则为非法指令MOVAL 050AH X 050Ah为字 而AL为字节寄存器有明确的字节或字类型 有寄存器参与的指令其操作数类型就是寄存器的类型对于存储器单元与立即数同时作为操作数的情况 必须显式指明 byteptr指示字节类型 wordptr指示字类型 两个操作数不能都是存储器 8086指令系统不允许两个操作数都是存储单元 除串操作指令 要实现这种传送 可通过寄存器间接实现movax buffer1 ax buffer1 buffer1内容送ax movbuffer2 ax buffer2 ax 这里buffer1和buffer2是两个字变量 实际表示直接寻址方式 Examples 要小心段寄存器的操作 不允许立即数传送给段寄存器MOVDS 100H 非法指令 立即数不能传送段寄存器不允许直接改变CS值MOVCS SI 不允许使用的指令不允许段寄存器之间的直接数据传送MOVDS ES 非法指令 不允许段寄存器间传送 xchg XCHGInstructionFormat XCHGswapsthetwodataitems 将两个不同地址的数据进行交换 2 交换指令xchg exchange XCHGswapsthetwodataitems movcx axmovax bxmovbx cx xchgcx bx Examples Note NotallowexchangingbetweenmemorytomemoryNotallowusingsegment register Anyaddressingmoldexceptingimmediate addressingNotaffectflag bit 寄存器与寄存器 存储器之间交换数据 但不能用xchg交换两个存储器操作数 不能用立即数 reg to reg movax 1234h ax 1234hmovbx 5678h bx 5678hxchgax bx ax 5678h bx 1234hxchgah al ax 7856h Examples 寄存器与存储器交换xchg xchgax 2000h xchg 2000h axxchgal 2000h 字节交换 等同于xchg 2000h al Examples XCHG指令 AddresstransferinstructionLEA loadeffectiveaddress 有效地址传送指令 Format LEAr16 mem REG Effective Addressofsourceoperand AddresstransferinstructionLEA LoadeffectiveaddressNotthephysicaladdressNotthecontentoftheunit Examples LEA指令 TheLEAInstruction Leaisusefulforinitializingaregisterwithanoffsetaddress AcommonuseofLEAistoinitializeanoffsetinBX DI orSIforindexinganaddressinmemory Datatbldb25dup tableof25bytesByteflddb onebyte Leabx datatbl loadoffsetaddressMovbytefld bx movefirstbyteofdatatbl Examples Whocanfindtheerror Datatbldb25dup tableof25bytesByteflddb onebyte Leabx datatbl loadoffsetaddressMovbytefld bx movefirstbyteofdatatbl Examples Movbytefld bx movefirstbyteofdatatbl TheLEAInstruction AnequivalentoperationtoLEAisMOVwiththeOFFSEToperator Leabx datatblMovbx offsetdatatbl IntegerAdditionandSubtractionInstructions整数的加法和减法指令addsubadcsbbincdecnegcmp 4 2 ArithmeticInstructions Additioninstruction ADD ADC INCSubtractioninstruction SUB SBB DECNEG CMPMultiplication MUL IMULDivision DIV IDIV TheADD SUBInstruction 加减法指令 Format Whenanadd subinstructionisexecuted Theintegeratsourceisadded subtractedtotheintegeratdestinationandthesum resultreplacestheoldvalueatdestination add subdestination source TheADD SUBInstruction 加减法指令 Operation DST DST SRC FlagsaffectedareSF ZF OF PF AF andCF add subDST SRC TheADD SUBInstruction 加减法指令 Therearenodirectmemorytomemory add subdst srcReg Mem Reg Mem Imm reg reg imm reg mem Mem Reg Imm Example MOVDL 12HADDDL 33HExecuted DL sum 45H Flags Z 0 result 0 C 0 nocarry A 0 noauxiliarycarry S 0 resultispositive P 0 parityisodd O 0 nooverflow TheAddinstructions moval 0fbhaddal 07hmovwordptr 200h 4652hmovbx 1fehaddal bladdwordptr bx 2 0f0f0h Foreachoftheunrelatedinstructions showtheresultinthedestinationoperand Examples TheAddinstructions moval 0fbh al 0fbhaddal 07h al 02hmovwordptr 200h 4652h 200h 4652hmovbx 1feh bx 1fehaddal bl al 00haddwordptr bx 2 0f0f0h 200h 3742h Answers Foreachoftheunrelatedinstructions showtheresultinthedestinationoperand TheSUBinstructions moval 0fbhsubal 07hmovwordptr 200h 4652hmovbx 1fehsubal blsubwordptr bx 2 0f0f0h Foreachoftheunrelatedinstructions showtheresultinthedestinationoperand Examples TheSUBinstructions moval 0fbh al 0fbhsubal 07h al 0f4h CF 0movwordptr 200h 4652h 200h 4652hmovbx 1feh bx 1fehsubal bl al 0f6h CF 1subwordptr bx 2 0f0f0h 200h 5562h CF 1 Answers ADC Additionwithcarry 带进位加法指令 Operation DST DST SCR CF ADCreg imm reg mem reg reg imm reg mem CFADCmem imm reg mem mem imm reg CF Format ADCdst src ADC movax 4652haddax 0f0f0hmovdx 0234hadcdx 0f0f0h Showtheresultinthedestinationoperand Question movax 4652h ax 4652haddax 0f0f0h ax 3742h CF 1movdx 0234h dx 0234hadcdx 0f0f0h dx f325h CF 0 DX AX 02344652H F0F0F0F0H F3253742H Answers ADC performingarithmeticondouble wordvaluesAdditionBX AXtoDX CX storeresultinBX AX TheADCInstruction Examples SUMPROCNEARADDAX CXADCBX DXRETSUMENDP SBB Subtractionwithborrow 带借位减法指令 Operation DST DST SCR CF SBBreg imm reg memreg reg imm reg mem CFSBBmem imm reg mem mem imm reg CF Format SBBdst src SBB movax 4652hsubax 0f0f0hmovdx 0234hsbbdx 0f0f0h Showtheresultinthedestinationoperand Examples SBB movax 4652h ax 4652hsubax 0f0f0h ax 5562h CF 1movdx 0234h dx 0234hsbbdx 0f0f0h dx 1143h CF 1 DX AX 02344652H F0F0F0F0H 11435562H Examples INC increment 增量指令 Format Operation DST DST 1INCinstructionclearorsettheOF SF andZFflags butnoteffectCFflagbit INC指令不影响进位CF标志 按定义设置其他状态标志 INCDST INC ADD INC increment 增量指令 Examples INCreg mem reg mem reg mem 1 incbxinc DI X assemblerdon tknowbyte wordord word incbyteptr bx DEC decrement 增量指令 Format Operation DST DST 1DECinstructionclearorsettheOF SF andZFflags butnoteffectCFflagbit DEC不影响进位CF标志 按定义设置其他状态标志 DECDST DEC decrement 减量指令 Examples DECreg mem reg mem reg mem 1 DECcxDECwordptr bx INCDEC Usefulforincrementinganddecrementingcounters Takefewerbytesofcodeandexecuteinfewerclockcyclesthancorrespondingadditionorsubtractioninstructions INC指令和DEC指令都是单操作数指令主要用于对计数器和地址指针的调整 NEG negate 取补指令 Format Function reversesthesignofabinaryvalue frompositivetonegativeandviceversa NEGreg mem reg mem 0 reg mem NEG negate 取补指令 Format Operation NEGreversesthebits andthenadds1forproper2 scomplementnotation DST 0 DST NEGinstructionaffectAF CF OF PF SFandZF NEGreg mem reg mem 0 reg mem NEG movax 0ff64hnegalsubal 9dhnegaxdecalnegax Questions Showtheresultinthedestinationoperand NEG movax 0ff64hnegal ax ff9ch OF 0 SF 1 ZF 0 PF 1 CF 1subal 9dh ax ffffh OF 0 SF 1 ZF 0 PF 1 CF 1negax ax 0001h OF 0 SF 0 ZF 0 PF 0 CF 1decal ax 0000h OF 0 SF 0 ZF 1 PF 1 CF 1negax ax 0000h OF 0 SF 0 ZF 1 PF 1 CF 0 Answers CMP compare 比较指令 Format Function Comparesthebinarycontentsoftwodatafields CMPDST SRC DST SRC CMP compare 比较指令 Format Operation CMPinternallysubtractsoperand2fromoperand1andsets clearsflags butnotstoretheresult Bothoperandsarebyte word ordoubleword DST SRC CMPDST SRC DST SRC CMP compare 比较指令 affectAF CF OF PF SFandZF CMPDST SRC DST SRC CMP compare 比较指令 CMPmaycompareregister memory orimmediatetoaregisterormaycompareregisterorimmediatetomemory CMPreg imm reg mem reg imm reg memCMPmem imm reg mem imm reg CMP cmpal 100 al 100jbbelow al 100 跳到belowsubal 100 al 100 al al 100incah ah ah 1below Examples 加法指令 减法指令 AdditionandSubtractionof2 sComplement补码的加减 1 4 ProcessingUnsignedandSignedBinaryData Forunsigneddata allbitsareintendedtobedatabits Forsigneddata theleftmostbitisasignbit SomeexampleshowhowtheadditionsettheCFandOF 1 TheadditiondoesnotsettheOForCF Theresultisthesameforbothunsignedandsigneddata 2 TheadditionsetOFandclearCF ArithmeticCarry Whereacarryoccursonunsigneddata thearithmeticresultisinvalid 3 ArithmeticOverflow AnarithmeticoperationsetstheOFwhenacarryintothesignbitdoesnotcarryout oracarryoutoccurswithnocarryin Ifanoverflowoccursonsigneddata thearithmeticresultisinvalid 4 BothOFandCFAreSet AnarithmeticoperationmaysetbothOFandCF Overflow P219 Overflowoccurswhenthenumberofcarriesintothesignpositionisdifferentfromthenumberofcarriesoutofthesignposition CFvs OF Cbitrepresentsoverflowforunsigneddata Thereiscarry C 1 otherwiseC 0 Forunsigneddataleftbitisdata not ssign sothecarryfromthisbitisarealcarryoftheresult butItexplainstheoverflowoftheresultinlimitedbitsrange Orepresentsoverflowforsigneddata ProcessingUnsignedandSignedBinaryData Forunsigneddata allbitsareintendedtobedatabits Forsigneddata theleftmostbitisasignbit Note theADDandSUBinstructionsdonotdistinguishbetweenunsignedandsigneddata CPU不知道操作数是有符号还是无符号 只是根据操作结果设置各种状态标志 由程序员自行选择使用或者忽略各个标志 Test Eachoftheseproblemsgives before conditionsandaninstruction Fillintheblankstoshowthe after state 4 3 Multiplication乘法指令 Thebasicmultiplicationoperationsarebytetimebyte wordtimesword double wordtimesdouble word 80386andlaterprocessors 字节量相乘或字量相乘或双字量相乘BothaffecttheCFandOF AF PF SF andZFareundefined MUL UnsignedMultiply 无符号数乘法指令 Multipliesanunsignedmultiplicand 被乘数 byanunsignedmultiplier 乘数 MULtreatsaleftmost1 bitasadatabit notanegativesign MUL UnsignedMultiply 无符号数乘法指令 Operation assumesthemultiplicandisinAL AXorEAX andtakesitssizefromthatofthemultiplier Thegeneratedproductisdouble multiplicator MULreg8 mem8 无符号字节乘法 AX AL r8 m8MULreg16 mem16 无符号字乘法 DX AX AX r16 m16 Table13 7bytemutiplication Table13 8wordmutiplication Table13 9Double wordmutiplication IMUL Signed Integer Multiply 有符号数乘法指令 Multipliesansignedmultiplicandbyansignedmultiplier IMULtreatstheleftmostbitasthesign IMUL Signed Integer Multiply Operation assumesthemultiplicandisinAL AXorEAX andtakesitssizefromthatofthemultiplier Theproductisdouble multiplicator IMULr8 m8 有符号字节乘 AX AL r8 m8IMULr16 m16 有符号字乘 DX AX AX r16 m16 multiply moval 0b4hmovbl 11hmulblmoval 0b4hmovbl 11himulbl Examples Showtheresultinthedestinationoperand multiply moval 0b4h al b4h 180movbl 11h bl 11h 17mulbl ax Obf4h 3060 OF CF 1 AX高8位不为0moval 0b4h al b4h 76movbl 11h bl 11h 17imulbl ax faf4h 1292 OF CF 1 AX高8位含有效数字 Answers 4 4 DivisionInstructions Thebasicdivideoperationsarebyteintoword wordintodoubleword DivisionInstructions ByteintoWord todividebyteintoword thedividend 被除数 isinAXandthedivisor 除数 isabyteinmemoryoranotherregister Theoperationstorestheremainder 余数 inAHandquotient 商 inAL 源操作数是字节量 被除数是字长度 存放在AX中商存放在AL中 余数存

温馨提示

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

最新文档

评论

0/150

提交评论