Thiết kế và lập trình hệ thống - Chương
✂✁✄☎ ✆✝✄✞✠✟✡☛✟☞✝✝✌✎✍☛✏✑✒✏✓✔✄✄✆✝✕✖✁✗✘ ✙✞✚✛✜✑1✢✔✎✣✟✌✖✤✑✦✥✤✑✑✜✧✎★✩✪☞✝✫UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6✬✎✭✮✠✯✰✱✲✲✯✳✴✰✎✵StringOperations.MOVS,LODS,STOS,INS,OUTSAllowdatatransfersofabyte,awordoradoubleword,orifrepeated,ablockofeachofthese.TheDflag-bit(direction),SIandDIareimplicitlyused.•D=0:AutoincrementDIandSI.UseCLDinstructiontoclearthisflag.•D=1:AutodecrementDIandSI.UseSTDinstructiontosetit.DI:Accessesdataintheextrasegment.CanNOToverride.SI:Accessesdatainthedatasegment.Canbeoverriddenwithsegmentoverrideprefix. ✂✁✄☎ ✆✝✄✞✠✟✡☛✟☞✝✝✌✎✍☛✏✑✒✏✓✔✄✄✆✝✕✖✁✗✘ ✙✞✚✛✜✑2✢✔✎✣✟✌✖✤✑✦✥✤✑✑✜✧✎★✩✪☞✝✫UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6✬✎✭✮✠✯✰✱✲✲✯✳✴✰✎✵StringOperations.LODS:LoadsAL,AXorEAXwithdatastoredatthedatasegment(orextrasegment)+offsetgivenbySI.SIisincrementedordecrementedafterwards:STOSB:StoresAL,AXorEAXtotheextrasegment(ES)+offsetgivenbyDI.EScannotbeoverridden.DIisincrementedordecrementedafterwards:LODS ✁✂✁✄☎✆✁✝✞ ✟✠✡✟☛☞☎✟☛✞✟☛ ✌✍✏✎✑✒ ✓ ✁✂✁✄✔LODSB☎✁✕✞ ✟✠✡✟☛☞☎✟☛✞✟☛ ✌✍✏✎✄LODSD☎✆✁✝✞ ✟✠✡✟☛☞☎✟☛✞✟☛ ✌✍✏✎✑doubleword.LODS✆✟✠ ✁✂✁✄☎✖✘✗✙✚✚✒ ✛✙ ✟✜STOS ✁✂✁✄☎✆✟✠✡ ☛☞✞✁✝☎✟☛✞✟☛ ✌✍✏✎✢✒ ✓ ✁✂✁✄✔STOSB☎✆✟✠✡ ☛☞✞✁✕☎ ☛✞ ☛ ✌✍✏✎✄STOSD☎✆✟✠✡ ☛☞✞✆✁✝☎ ☛✞ ☛ ✌✍✏✎✑word. ✂✁✄☎ ✆✝✄✞✠✟✡☛✟☞✝✝✌✎✍☛✏✑✒✏✓✔✄✄✆✝✕✖✁✗✘ ✙✞✚✛✜✑3✢✔✎✣✟✌✖✤✑✦✥✤✑✑✜✧✎★✩✪☞✝✫UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6✬✎✭✮✠✯✰✱✲✲✯✳✴✰✎✵StringOperations:LODSWEAXEBXECXEDXESPEBPEDIESICSDSESSS ✁✂✁✄ ☎✆*10H✝✞✞✞+✝✞✞✞11000✟✞✠✡✟✞✠✡+/-2 ✂✁✄☎ ✆✝✄✞✠✟✡☛✟☞✝✝✌✎✍☛✏✑✒✏✓✔✄✄✆✝✕✖✁✗✘ ✙✞✚✛✜✑4✢✔✎✣✟✌✖✤✑✦✥✤✑✑✜✧✎★✩✪☞✝✫UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6✬✎✭✮✠✯✰✱✲✲✯✳✴✰✎✵StringOperations.REPprefix:ExecutestheinstructionCXtimes.NOTE:REPdoesnotmakesensewiththeLODSinstruction.CLD✜ ✖ ✆✕✂☛✁✂.STARTUPMOV AX✄☎ ✆✝☎☎ ✞.EXITEND☎✟✙✟✙✠✡✒☞☛✠✚✙✌✙☛✡✌✍✛✙✜.CODE☎✁✛✛✚✙✎✎✗✒ ✛✙✍✎✙✏✆✝☎☎✜MOV ES✄AXMOV DI✄☎☎✖✓✓✎✙✡☎✜MOV CX✄✢ ✑✒✝☎☎✕✍✔✛✠✍✓☛✡✜MOV AX✄☎ ✔✢☎ ✞☎✕✍✔✛✔✡✡✚✒ ✕✓✡✙✔☛✛✠✖✔✚✜✗✘✙✄✚✛✄✜☎✢✟✙✔✚✡✖✙✎✠✚✙✙☛✜ ✂✁✄☎ ✆✝✄✞✠✟✡☛✟☞✝✝✌✎✍☛✏✑✒✏✓✔✄✄✆✝✕✖✁✗✘ ✙✞✚✛✜✑5✢✔✎✣✟✌✖✤✑✦✥✤✑✑✜✧✎★✩✪☞✝✫UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6✬✎✭✮✠✯✰✱✲✲✯✳✴✰✎✵StringOperations.MOVS:Movesabyte,wordordoublewordfromdatasegmentandoffsetSItoextrasegmentandoffsetDI.Increments/decrementsbothDIandSI:INS/OUTS(notavailableonthe8086):Transfersabyte,wordordoublewordofdatafrom/toanI/Odeviceinto/outoftheextra/datasegment+offsetDI/SI,respectively.TheI/OaddressisstoredintheDXregister.MOVS✆✄✄✆✢☎✆✟✠✡ ☛☞✞ ✟✠✡✟☛☞☎ ☛✞ ☛✌✍✏✎✄☎✟☛✞✟☛ ✌✍✏✎✄MOVSB☎✆✟✠✡ ☛☞✞ ✟✠✡✟☛☞☎ ☛✞ ☛ ✌✍✏✎✄☎✟☛✞✟☛ ✌✍✏✎✄MOVSD☎✆✟✠✡ ☛☞✞ ✟✠✡✟☛☞☎ ☛✞ ☛✌✍✏✎✑☎✟☛✞✟☛ ✌✍✏✎✑ ✁✄✜✂✄✄✂✢☎✆✟✠✡ ☛☞✞✡ ✝☞☎ ☛✞ ☛ ✌✍✏✎✢☎✟☛✞✟☛ ✌✍✏✎✢INSB☎✆✟✠✡ ☛☞✞✡ ✝☞☎ ☛✞ ☛✌✍✏✎✄INSD☎✆✟✠✡ ☛☞✞✡ ✝☞☎ ☛✞ ☛ ✌✍✏✎✑OUTSB☎✡ ✝☞✞ ✟✠✡✟☛☞☎✟☛✞✟☛ ✌✍✏✎✄ ✂✁✄☎ ✆✝✄✞✠✟✡☛✟☞✝✝✌✎✍☛✏✑✒✏✓✔✄✄✆✝✕✖✁✗✘ ✙✞✚✛✜✑6✢✔✎✣✟✌✖✤✑✦✥✤✑✑✜✧✎★✩✪☞✝✫UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6✬✎✭✮✠✯✰✱✲✲✯✳✴✰✎✵StringOperations.INSExample:NOTE:Thisassumesthedeviceisabletomakedataavailableatthespeedoftheprogram,andinsyncwiththeprogram.Sincethisisalmostnevertrue,thecodeaboveneedstohavea“devicestatuscheck”instruction(s).Ofcourse,theREPprefixcannotbeusedinthiscase.ThesameholdstrueforOUTSinstructions.LEA DI✄✕☛✟✂☎✁✛✛✚✙✎✎✔✚✚✔ ✜MOV DX✄✁✁✢✞☎✟✍✌✙☛✍✖✛✙✗✒✠✙✔✛✛✚✙✎✎✜MOV CX✄✑☎✗✘✙ ✁✄✂☎✄✙✡✡✖✙✛✔✡✔✜ .CLD . ✂✁✄☎ ✆✝✄✞✠✟✡☛✟☞✝✝✌✎✍☛✏✑✒✏✓✔✄✄✆✝✕✖✁✗✘ ✙✞✚✛✜✑7✢✔✎✣✟✌✖✤✑✦✥✤✑✑✜✧✎★✩✪☞✝✫UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6✬✎✭✮✠✯✰✱✲✲✯✳✴✰✎✵MiscellaneousDataTransferOperations.XCHG:Exchangesthecontentsofaregisterwiththecontentsofanyotherregisterormemorylocation.ItcanNOTexchangesegmentregistersormemory-to-memorydata.Byte,wordanddoublewordscanbeexchangedusinganyaddressingmode(exceptimmediate,ofcourse).XLAT:PerformsatablelookupoperationbyconvertingthevalueinALfromanindextoavaluestoredinthecellofatableinmemory. ✁✂✄EDX✄ESI☎✆✆☎✠✖✔☛✏✙✆ ✝✔☛✛✆✟☛ ✁✂✄AL✄ ✁✂✁✢☎✆☎✠✖✔☛✏✙✚✙✏✒✎✡✙✚✔☛✛✌✙✌✍✚ ✗✔✟✓✙✎✜MOV AL✄✑☎✕✍✔✛✒☛✛✙☎✜XLAT .✝✘✟BX✄✖✞✞✟✆✂✂✁✆✕✆☎✆✔✎✙✔✛✛✚✙✎✎✍✓✡✔✕✟✙✜☎✟✟✔✠✕ ✡✙✔✡✁✕✌✆✝✌ ✟✟✒✡✖✁✕✜ . ✂✁✄☎ ✆✝✄✞✠✟✡☛✟☞✝✝✌✎✍☛✏✑✒✏✓✔✄✄✆✝✕✖✁✗✘ ✙✞✚✛✜✑8✢✔✎✣✟✌✖✤✑✦✥✤✑✑✜✧✎★✩✪☞✝✫UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6✬✎✭✮✠✯✰✱✲✲✯✳✴✰✎✵MiscellaneousDataTransferOperations.INandOUT:Transfersabyte,wordordoublewordofdatafrom/toanI/Odeviceinto/outofAL,AXandEAX,respectively.Memoryoperationsarenotavailable(astheyareinINSandOUTS):Twoforms:•Fixed-portaddressing:8-bitportnumberencodedininstruction.8-bitvalueissign-extendedintoaddressbits8-15.Addressbits16-31areundefined.•Variable-portaddressing:16-bitportnumberstoredinDX. ✁AL✄✠✝☎✝ ✎✕✒✡✎✔✚✙✎✔✗✙✛✡✍✁✕✓✚✍✌☛✍✖✠✍✚✡✠✝✜ ✁EAX✄✠✝☎✁✢✎✕✒✡✎✔✚✙✎✔✗✙✛✡✍✆✁✝✜✛ ✚DX✄EAX☎✁✢✎✕✒✡✎✔✚✙✟✚✒✡✡✙☛✡✍✠✍✚✡ ✝✓✚✍✌✆✁✝✜ ✂✁✄☎ ✆✝✄✞✠✟✡☛✟☞✝✝✌✎✍☛✏✑✒✏✓✔✄✄✆✝✕✖✁✗✘ ✙✞✚✛✜✑9✢✔✎✣✟✌✖✤✑✦✥✤✑✑✜✧✎★✩✪☞✝✫UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6✬✎✭✮✠✯✰✱✲✲✯✳✴✰✎✵MiscellaneousDataTransferOperations.INandOUTExample:Notethattheoldcontentsofthehigher-orderbitpositionsoftheportarepreserved.IN AL✄ ✄ ✞✜ ✖ ✆✕✂☛✁✂.STARTUPOR AL✄✁.EXITEND☎✁✙✔✛✠✍✚✡ ✄ ✞✂✎✠✙✔✄✙✚☎✜.CODE☎✟✙✡✚✒✏✖✡✌✍✎✡✡✟✍✕✒✡✎✜OUT ✄ ✞✄ALLOOP✕✄☎✂✒✌✙✛✙✟✔ ✜IN AL✄ ✄ ✞☎✁✙✔✛✠✍✚✡ ✄ ✞✜AND AL✄☎✞✢✞☎✢✟✙✔✚✚✒✏✖✡✌✍✎✡✡✟✍✕✒✡✎✜✛ ✚ ✄ ✞✄AL☎✟✠✙✔✄✙✚✍✓✓✜☎✂✓✚☛✍☛✡✖✙✎✠✙✔✄✙✚✜MOV CX✄✄☎☎☎ ✞☎ ✙✟✔ ✠✍✓☛✡✜L1: ✂✁✄☎ ✆✝✄✞✠✟✡☛✟☞✝✝✌✎✍☛✏✑✒✏✓✔✄✄✆✝✕✖✁✗✘ ✙✞✚✛✜✑10✢✔✎✣✟✌✖✤✑✦✥✤✑✑✜✧✎★✩✪☞✝✫UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6✬✎✭✮✠✯✰✱✲✲✯✳✴✰✎✵MiscellaneousDataTransferOperations.MOVSXandMOVZX(80386anduponly):Move-and-sign-extendandMove-and-zero-extend:BSWAP(80486anduponly):Swapsthefirstbytewiththeforth,andthesecondbytewiththethird.Usedtoconvertbetweenlittleendianandbigendian: ✛✁✄ CX✄BL☎✟✒✏☛✎✙☎✡✙☛✛✎✆✕✒☛✡✍✢✝ ✛✁✂ EAX✄ ✁✂✁✢☎✄✙✚✍✙☎✡✙☛✛✎✟✍✚✛✔✡ ✁✂✁✢✒☛✆✆☎✜✂✄✜✟✙EAXEAXEBXECXEDX✡✡✠✠✞✞✝✝✝✝✞✞✠✠✡✡ . 6✬✎✭✮✠✯✰✱✲✲✯✳✴✰✎✵MiscellaneousDataTransferOperations.INandOUT:Transfersabyte,wordordoublewordofdatafrom/toanI/Odeviceinto/outofAL,AXandEAX,respectively.Memoryoperationsarenotavailable(astheyareinINSandOUTS):Twoforms:•Fixed-portaddressing:8-bitportnumberencodedininstruction.8-bitvalueissign-extendedintoaddressbits 8-1 5.Addressbits1 6-3 1areundefined.•Variable-portaddressing:16-bitportnumberstoredinDX. ✁AL✄✠✝☎✝. 6✬✎✭✮✠✯✰✱✲✲✯✳✴✰✎✵MiscellaneousDataTransferOperations.MOVSXandMOVZX(80386anduponly):Move-and-sign-extendandMove-and-zero-extend:BSWAP(80486anduponly):Swapsthefirstbytewiththeforth,andthesecondbytewiththethird.Usedtoconvertbetweenlittleendianandbigendian: ✛✁✄ CX✄BL☎✟✒✏☛✎✙☎✡✙☛✛✎✆✕✒☛✡✍✢✝ ✛✁✂ EAX✄ ✁✂✁✢☎✄✙✚✍✙☎✡✙☛✛✎✟✍✚✛✔✡ ✁✂✁✢✒☛✆✆☎✜✂✄✜✟✙EAXEAXEBXECXEDX✡✡✠✠✞✞✝✝✝✝✞✞✠✠✡✡ ✂✁✄☎