版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第四章
8086指令系统4.1汇编语言程序4.28068寻址方式4.38086指令系统4.4程序设计步骤内容与要求:
1.熟悉Intel8086/8088的寻址方式。
2.掌握Intel8086/8088的指令系统。
3.了解Intel80386扩充与增加的指令。4.1汇编语言程序(1)机器语言(MachineLanguage)
机器语言是一种用二进制表示指令和数据,能被机器直接识别的计算机语言。它的缺点是不直观,不易理解和记忆,因此编写、阅读和修改机器语言程序都比较繁琐。但机器语言程序是计算机惟一能够直接理解和执行的程序,具有执行速度快、占用内存少等特点。(2)汇编语言(AssemblyLanguage)
汇编语言是一种采用助记符表示的程序设计语言,即用助记符来表示指令的操作码和操作数,用标号或符号代表地址、常量或变量。助记符一般都是英文字的缩写,以方便人们书写、阅读和检查。实际上,用汇编语言编写的汇编语言源程序就是机器语言程序的符号表示,汇编语言源程序与其经过汇编所产生的目标代码程序之间有明显的一一对应关系,故也称汇编语言为符号语言。例题:1.定义问题:
已知某日的最高温度和最低温度,要求计算这一天的平均温度。2.算法设计: 最高温度加最低温度 将和除以2得到平均温度3.数据结构:
DATASEGMENTHI_TEMPDB92H;实际值可能是从传感器读取的数值LO_TEMPDB52H AV_TEMPDB? DATAENDS4.初始化表: MOVAX,DATA MOVDS,AX5.选择指令:
选择算法中每一主要动作所需的指令(按功能选择指令),并决定数据在这些指令中的存放形式,最后则按照指令的要求,用MOV或其他的指令把数据传送的正确的位置。
ADDdest,source;查指令表并阅读细节ADCdest,source;dest=dest+source+CFDIVsource;DIV02immedmodenotallowed!!6.编写程序:DATASEGMENTHI_TEMPDB92HLO_TEMPDB52HAV_TEMPDB?DATAENDSCODE SEGMENTMAIN PROC FAR
ASSUMECS:CODE,DS:DATA MOV AX, DATA MOV DS, AX MOV AL, HI_TEMP ADD AL, LO_TEMP MOV AH, 00H ADC AH, 00H MOV BL, 02 DIV BL MOV AV_TEMP,AL
MOV AH, 4CH INT 21HMAIN ENDPCODE ENDS
ENDMAINExample: PURPOSE:ADDS4WORDSOFDATA
STACK SEGMENT
DB 32DUP(?) STACK ENDS DATA SEGMENT data_in DW 234DH,1DE6H,3BC7H,566AH
ORG 10H sum DW ? DATA ENDS CODE SEGMENT MAIN PROC FAR
ASSUMECS:CODE,DS:DATA,SS:STACK MOV AX, DATA MOV DS, AX MOV CX, 04 MOV DI, OFFSETdata_in MOV BX, 00 ADD_LP: ADD BX, [DI] INC DI INC DI DEC CX JNZ ADD_LP MOV SI, OFFSETsum MOV [SI], BX MOV AH, 4CH INT 21H MAIN ENDP CODE ENDS
END MAIN ;FULLSEGMENTDEFINITION ;-----stacksegment-------- STACK SEGMENT
DB 64DUP(?) STACK ENDS ;-----datasegment-------- DATA SEGMENT ;datadefinitionsareplacedhere DATA ENDS ;-----codesegment-------- CODE SEGMENT MAIN PROCFAR
ASSUMECS:CODE,DS:DATA,SS:STACK MOVAX, DATA MOVDS, AX ------ MOVAH, 4CH INT21H MAIN ENDP CODE ENDS ENDMAIN4.28086寻址方式(Addressingmodes)
指令以不同的方式访问操作数(数据)称为寻址方式。
8086共有7种寻址方式:(1)寄存器寻址(register)(2)立即寻址(immediate)(3)直接寻址(direct)(4)寄存器间接寻址(registerindirect)(5)基址相对寻址(basedrelative)(6)变址相对寻址(indexedrelative)(7)基址变址相对寻址(basedindexedrelative)操作数在CPU内:(1)寄存器寻址(Register): MOVBX,DX MOVES,AX ADDAL,BH
MOVCL,AX(2)立即寻址(immediate): MOVAX,2550H MOVCX,625 MOVBL,40H MOVAX,2550H MOVDS,AX MOVDS,0123H操作数在CPU外:(3)直接寻址(direct):
MOV
DL,[2400];movecontentsofDS:2400HintoDLPA=DS*10H+2400Example: Findthephysicaladdressofthememorylocationanditscontentsaftertheexecutionofthefollowing,assumingthatDS=1512H. MOV AL,99H MOV [3518],ALSolution: FirstALisinitializedto99H,theninlinetwo,thecontentsofALaremovedtologicaladdressDS:3518whichis1512:3518.ShiftingDSleftandaddingittotheoffsetgivesthephysicaladdressof18638H(15120H+3518H).Thatmeansaftertheexecutionofthesecondinstruction,thememorylocationwithaddress18638Hwillcontainthevalue99H.(4)寄存器间接寻址(registerindirect):MOVAL,[BX]
;movesintoALthe;contentsofthe;memorylocation;pointedtobyDS:BX
MOVCL,[SI]
MOV
[DI],AHExample: AssumethatDS=1120,SI=2498,andAX=17FE.Showthecontentsofmemorylocationsaftertheexecution MOV [SI],AXSolution: ThecontentsofAXaremovedintomemorylocationswithlogicaladdressDS:SIandDS:SI+1;therefore,thephysicaladdressstartsatDS*10H(shiftedleft)+SI=13698.Accordingtothelittleendianconvention,lowaddress13698HcontainsFE,thelowbyte,andhighaddress13699Hwillcontain17,thehighbyte.Strcpy函数:将指针d指向的字符串复制到指针s指向的位置—寄存器间接寻址法 viod strcpy(char*s,char*d) { while((*s=*d)!=‘\0’){ s++; d++; } }(5)基址相对寻址(basedrelative)MOV
CX,[BX]+10;PA=DS*10H+BX+10
MOVAL,[BP]+5;PA=SS*10H+BP+5
MOVAL,[BP+5]
MOVAL,5[BP](6)变址相对寻址(indexedrelative)
MOVDX,[SI]+5;PA=DS*10H+SI+5
MOVCL,[DI]+20
;PA=DS*10H+DI+20Example:
AssumethatDS=4500,SS=2000,BX=2100,SI=1486,BP=7814,andAX=2512.ShowtheexactphysicalmemorylocationwhereAXisstoredineachofthefollowing.Allvaluesarehex. (a) MOV [BX]+20,AX (b) MOV [SI]+10,AX (c) MOV [DI]+4,AX (d) MOV [BP]+12,AXSolution:
IneachcasePA=segmentregister(shiftedleft)+offsetregister+displacement. (a) DS:BX+20 location47120=(12)and47121=(25) (b) DS:SI+10 location46496=(12)and46497=(25) (c) DS:DI+4 location4D504=(12)and4D505=(25) (d) SS:BP+12 location27826=(12)and27827=(25)#include <stio.h>
#define PROFIT 15
#define MAX_PRICES 10Int cost[]={20,28,15,26,19,27,16,29,39,42};Int prices[10];Int index;Main(){ for(index=0;index<MAX_PRICES;index++) prices[index]=cost[index]+PROFIT}Strcpy函数:将指针d指向的字符串复制到指针s指向的位置—基址相对寻址法Voidstrcpy(char*s,char*d){ int i; i=0; while((s[i]=d[i]!=‘\0’) i++;}(7)基址变址相对寻址(basedindexedrelative)
MOVCH,[BX][SI]+20
;PA=DS*10H+BX+SI+20(7)基址变址相对寻址(basedindexedrelative)
MOVCL,[BX][DI]+8 ;PA=DS*10H+BX+DI+8 MOVCL,[BX+DI+8] MOVCH,[BX][SI]+20 ;PA=DS*10H+BX+SI+20
MOVAH,[BP][DI]+12
;PA=SS*10H+BP+DI+12 MOVAH,[BP][SI]+29 ;PA=SS*10H+BP+SI+29
MOVAX,[SI][DI]+displacementAddressingModeOperandDefaultSegmentRegisterRegNone(CPU)ImmediateDataNone(CPU)Direct[offset]DSRegisterindirect[BX][SI][DI]DSDSDSBasedrelative[BX]+disp[BP]+dispDSSSIndexedrelative[DI]+disp[SI]+dispDSDSBasedindexedrelative[BX][SI]+disp[BX]+[DI]+disp[BP]+[SI]+disp[BP]+[DI]+dispDSDSSSSS4.38086
指令系统指令(Instruction)和伪指令(Directives)格式:
[标号:]助记符[操作数][;注释]
[label:]mnemonic[operands][;comment]指令(Instruction):
4.3.1数据传送类指令
4.3.2算术运算指令
4.3.3位操作指令
4.3.4串操作指令
4.3.5程序转移指令
4.3.6处理机控制指令4.3.1数据传送类指令
(1)MOV(MOVement) MOVdst,src;copysrctodst MOVCL,55H MOVDL,CL MOVAH,DL MOVAL,AH MOVBH,CL MOVCH,BH
MOVCX,468FH MOVAX,CX MOVDX,AXMOVBX,DXMOVDI,BXMOVSI,DIMOVDS,SIMOVBP,DIMOVAX,58FCHMOVDX,6678HMOVSI,924BHMOVBP,2459HMOVDS,2341HMOVCX,8876HMOVCS,3F47HMOVBH,99H指令格式中的dst表示目的操作数,src表示源操作数(下同)。指令实现的操作是将源操作数送给目的操作数。这种传送实际上是进行数据的“复制”,源操作数本身不变。这种双操作数指令在汇编语言中的表示方法,总是将目的操作数写在前面,源操作数写在后面,二者之间用一个逗号隔开。必须注意,不能用一条MOV指令实现以下传送:①存储单元之间的传送。②立即数至段寄存器的传送。③段寄存器之间的传送。(2)LEA(LoadEffectiveAddress) Format:LEAdst,src ;dst=OFFSETsrc Flags:Unchanged. Function:Loadsintothedestination(a16-bitregister)theeffectiveaddressofadirectmemoryoperand.
ORG 0100HDATA DB 34,56,87,90,76,54,13,29 … ;toaccessthesixthelement: LEA SI, DATA+5 ;SI=100H+5 MOV AL, [SI];ifBX=2000H;SI=3500HLEADX,[BX][SI]+100H;DX=2000+3500+100;=5600H(3)PUSH(PUSHwordontostack)Format:PUSHsrc;SP=SP-2Flags:Unchanged.Function:CopiesthesourcewordtothestackanddecrementsSPby2.PUSHAXPUSHDIPUSHDX(4)POP(POPwordoffstack)Format:POPdst;SP=SP+2Flags:Unchanged.Function:CopiesthewordpointedtobythestackpointertotheregisterormemorylocationindicatedbytheoperandandincrementstheSPby2.
POPDXPOPDIPOPAX(5)XCHG(eXCHanGe)Format:XCHGdst,srcFlags:Unchanged功能:将源地址与目的地址中的内容互换。MOV AX,5678H ;(AX)=5678HMOV BX,0FFFFH ;(BX)=0FFFFHXCHG AX,BX;(AX)=0FFFFH,(BX)=5678H4.3.2算术运算指令(1)加1指令INC(INCrementby1) Format:INCdst ;dst=dst+1 Flags: OF,SF,ZF,AF,PF.Unchanged:CF
INC指令是一个单操作数指令,操作数可以是寄存器或存储器操作数。 如:INCBX,即(BX)+1→BX。 加1指令可用于对计数器和地址指针进行调整。
Example:Adds5bytesofdataSTACK SEGMENT
DW 64 DUP(?)STACK ENDSDATA SEGMENTdata_in DB 25H,12H,15H,1FH,2BHsum DB ?DATA ENDSCODE SEGMENTMAIN PROC
FAR
ASSUMECS:CODE,DS:DATA,SS:STACK
MOV AX, DATA MOV DS, AX
MOV CX, 05 MOV BX, OFFSETdata_in MOV AL, 0AGAIN: ADD AL, [BX] INC BX DEC CX JNZ AGAIN MOV SUM, AL
MOV AH, 4C INT 21HMAIN ENDPCODE ENDS END MAIN
(2)ADD(ADDition)Format:ADDdst,src ;dst=dst+src
Flags: OF,SF,ZF,AF,PF,CF
MOV AL, 25H MOV BL, 34H ADD AL, BL MOVDH, 25H MOVCL, 34H ADD DH, CL MOVDH, 25H ADDDH, 34H例题:;Thisprogramcalculatesthetotalsumof5bytesofdata.
.MODELSMALL .STACK64;--------------
.DATACOUNT EQU 05;equateDATA DB 125,235,197,91,48;definebyte
ORG 0008H;originSUM DW ?;defineword;--------------
.CODEMAIN PROC FAR MOV
AX,@DATA MOV
DS,AX
MOV CX,COUNT ;CXistheloopcounter
MOVSI,OFFSETDATA;SIisthedatapointerMOV AX,00 ;AXwillholdthesum
BACK:
ADD
AL,[SI] ;addthenextbytetoALJNC
OVER ;Ifnocarry,continueINC AH ;elseaccumulatecarryinAHOVER:
INC SI ;incrementdatapointerDEC CX ;decrementloopcounterJNZ BACK ;ifnotfinished,goaddnextbyte
MOV SUM,AX ;storesum
MOV AH,4CH
INT 21H ;gobacktoDOSMAINENDP
END MAIN(3)ADC(AdditionwithCarry)Format:ADC
dst,src ;dst=dst+src+CFFlags:OF,SF,ZF,AF,PF,CF;Thisprogramcalculatesthetotalsumoffivewordsofdata.
.MODELSMALL.STACK64;--------------
.DATACOUNT EQU 05DATA DW 27345,28521,29533,30105,32375;
ORG 0010HSUM DW 2DUP(?) ;duplicate;--------------
.CODEMAIN PROC FAR MOV AX,@DATA MOV DS,AX MOV CX,COUNT ;CXistheloopcounter MOV
SI,OFFSETDATA ;SIisthedatapointer
MOV AX,00 ;AXwillholdthesum
MOV BX,AX ;BXwillholdthecarriesBACK:
ADD
AX,[SI] ;addthenextwordtoAXADC BX,0 ;addcarrytoBXINC
SI ;incrementdatapointertwice
INC SI ;topointtonextwordDEC CX ;decrementloopcounter
JNZ
BACK ;ifnotfinished,continueadding
MOV SUM,AX ;storethesumMOV
SUM+2,BX ;storethecarries
MOVAH,4CH INT
21H ;gobacktoDOSMAINENDP
ENDMAIN;Thisprogramaddsthefollowingtwomultiwordnumbersandsavesthe;result:DATA1=548FB9963CE7HandDATA2=3FCD4FA23B8DH.
.MODELSMALL
.STACK64;--------------
.DATADATA1 DQ548FB9963CE7H ;definequadword
ORG0010HDATA2 DQ3FCD4FA23B8DH
ORG0020HDATA3 DQ?;--------------
.CODEMAIN PROC FAR MOV
AX,@DATA MOV DS,AX
CLC;clearcarrybeforefirstaddition
MOV
SI,OFFSETDATA1;SIispointerforoperand1MOVDI,OFFSETDATA2;DIispointerforoperand2
MOVBX,OFFSETDATA3;BXispointerforthesum
MOVCX,04;CXistheloopcounterBACK:MOVAX,[SI];movethefirstoperandtoAXADCAX,[DI];addthesecondoperandtoAXMOV[BX],AX;storethesumINCSI;pointtonextwordofoperand1INCSIINCDI;pointtonextwordofoperand2INCDIINCBX;pointtonextwordofsumINCBXLOOPBACK;ifnotfinished,continueadding
MOVAH,4CH INT21H;gobacktoDOS MAIN ENDP
ENDMAIN(4)
DEC(Decrement)Format:DEC
dest;dest=dest-1Flags:OF,SF,ZF,AF,PF.Unchanged:CFFunction:Subtract1fromthedestinationoperand.NotethatCFisunchangedevenifavalue0000isdecrementedandbecomesFFFF.(5)SUB(Subtract)Format:SUBdest,source;dest=dest-sourceFlags:OF,SF,ZF,AF,PF,CFFunction:Subtractssourcefromdestinationandputstheresultinthedestination.Setsthecarryandzeroflagaccordingtothefollowing:CFZFdest>source00theresultispositivedest=source01theresultis0dest<source10theresultisnegativein2`scomp ThestepsforsubtractionperformedbytheinternalhardwareoftheCPUareasfollows: 1.Takesthe2`scomplementofthesource 2.Addsthistothedestination 3.Invertsthecarryandchangestheflagsaccordingly;fromthedatasegmentDATA1DB4CHDATA2DB6EHDATA3DB?;fromthecodesegment MOV DH, DATA1 SUB DH, DATA2 JNC NEXT NOT DH INC DHNEXT: MOV DATA3,DH(6)SBB(SubtractwithBorrow)Format:SBBdest,source:dest=dest-CF-sourceFlags:OF,SF,ZF,AF,PF,CFExample:;fromthedatasegmentDATA_ADD62562FAHDATA_BDD412963BHRESULTDD?;fromthecodesegment MOV AX, WORD
PTRDATA_A SUB AX, WORDPTRDATA_B MOV WORD
PTRRESULT, AX MOV AX, WORDPTRDATA_A+2 SBB AX, WORDPTRDATA_B+2 MOV WORD
PTRRESULT+2,AX(7)CMP(CompareOperands)Format:CMPdest,source;setsflagsasif“SUB”Flags:OF,SF,ZF,AF,PF,CFFunction:Comparestwooperandsofthesamesize.Thesourceanddestinationoperandsarenotaltered.
CF ZF dest>source0 0 dest=source0 1 dest<source1 0Example: DATA1 DW 235FH ….. MOV AX,0CCCCH CMP AX,DATA1 JNC OVER SUB AX,AX OVER: INC DATA1 …..Example: ….. MOV BX,7888H MOV CX,9FFFH CMP BX,CX JNC NEXT ADD BX,4000H NEXT: ADD CX,250H …..Example: ….. TEMP DB ? ….. MOV AL,TEMP CMP AL,99 JZ HOT INC BX ….. HOT : HLTExample:;Thefollowingprogramfindsthehighestamong5grades.MODELSMALL.STACK64;--------------
.DATAGRADES DB 69,87,96,45,75
ORG 0008HIGHEST DB ?;--------------
.CODEMAIN PROC FAR MOV AX, @DATA MOV
DS, AX
MOVCX,5;setuploopcounter MOV
BX,OFFSETGRADES;BXpointsto GRADEdata SUBAL,AL;ALholdshighestgradefoundsofarAGAIN:CMPAL,[BX];comparenextgradetohighestJANEXT;jumpifALstillhighestMOVAL,[BX];elseALholdsnewhighestNEXT: INCBX;pointtonextgradeLOOPAGAIN;continuesearchMOVHIGHEST,AL;storehighestgradeMOV AH,4CHINT
21H;gobacktodosMAINENDP
ENDMAINExample:ASCIIlowercasetouppercaseconversion43217650000010100111001011101110000NULDLESP0@P\p0001SOHDC1!1AQaq0010STXDC2“2BRbr0011ETXDC3#3CScs0100EOTDC4$4DTdt0101ENQNAK%5EUeu0110ACKSYN&6FVfv0111BELETB‘7GWgw1000BSCAN(8HXhx1001HTEM)9IYiy1010LFSUB*:JZjz1011VTESC+;K[k{1100FFFS,<L\l|1101CRGS-=M]m}1110SORS.>N^n~1111SIUS/?O_oDEL行0123456789101112131415列01234567.MODELSMALL.STACK64;--------------
.DATADATA1DB 'mYNAMEisjOe'
ORG 0020HDATA2 DB 14DUP(?);--------------
.CODEMAIN PROC FAR MOV AX,@DATA MOV DS,AX MOV SI,OFFSETDATA1;SIpointstooriginaldata MOV BX,OFFSETDATA2;BXpointstouppercasedata MOV CX,14;CXisloopcounterBACK: MOV AL,[SI] ;getnextcharacter CMP AL,61H ;iflessthan'a'JBOVER;thennoneedtoconvert CMP AL,7AH ;ifgreaterthan'z'JAOVER;thennoneedtoconvert AND AL,11011111B ;maskd5toconverttouppercaseOVER: MOV [BX],AL ;storeuppercasecharacter INC SI ;incrementpointertooriginal INC BX ;incrementpointertouppercasedata LOOP BACK ;continueloopingifCX>0 MOV AH,4CH INT
21H ;gobacktodosMAIN ENDP
END MAIN4)十进制数(BCD)运算指令
1.压缩BCD码调整指令(1)加法的十进制调整指令DAA(2)减法的十进制调整指令DAS
2.非压缩BCD码调整指令(1)加法的非压缩BCD码调整指令AAA(2)减法的非压缩BCD码调整指令AAS(3)乘法的非压缩BCD码调整指令AAM(4)除法的非压缩BCD码调整指令AADKeyASCII(hex)BinaryBCD(unpacked)030011000000000000131011000100000001232011001000000010333011001100000011434011010000000100535011010100000101636011011000000110737011011100000111838011100000001000939011100100001001ASCII码ASCIItounpackedBCDconversion;-----------datasegmentASC DB ‘9562481273’
ORG 0010HUNPACK DB 10DUP(?);-----------codesegment MOV CX, 5 MOV BX, OFFSETASC MOV DI, OFFSETUNPACKAGAIN: MOV AX, [BX] AND AX, 0F0FH MOV [DI], AX ADD BX, 2 ADD DI, 2 LOOP AGAIN;-----------datasegmentASC DB ‘9562481273’
ORG 0010HUNPACK DB 10DUP(?);-----------codesegment
MOV CX, 10 SUB BX, BXAGAIN: MOV AL, ASC[BX] AND AL, 0FH MOV UNPACK[BX],AL INC BX LOOP AGAINASCIItopackedBCDconversionKey
ASCII
UnpackedBCD
PackedBCD434000001007370000011101000111(47H)Example:
ORG 0010HVAL_ASC DB ‘47’VAL_BCD DB ?;------------- MOV AX,WORDPTRVAL_ASC AND AX,0F0FH XCHG AH,AL MOV CL,4 ROL AH,CL OR AL,AH MOV VAL_BCD,AL;----------------PackedBCDtoASCIIconversionPackedBCD
UnpackedBCD
ASCII29H02H&09H32H&39H0010100100000010&000010010110010&0111001Example:VAL_BCD DB 29HVAL_ASC DW ?--------------- MOV AL, VAL_BCD MOV AH, AL AND AX, 0F00FH MOV CL, 4 SHR AH, CL OR AX, 3030H XCHG AH, AL MOV VAL_ASC,AX---------------(1)十进制加法的调整指令DAADAA(DecimalAdjustafterAddition)Format:DAA;NotethatDAAworksonlyonALFlags: Affected:SF,ZF,AF,PF,CF,OFExample:----------DATA1 DB 47HDATA2 DB 25HDATA3 DB ?---------- MOV AL, DATA1 MOV BL, DATA2 ADD AL, BL DAA MOV DATA3,AL---------- Example:1.ConvertfromASCIItopackedBCD2.AddthemultibytepackedBCDandsaveit3.ConvertthepackedBCDresultintoASCII
.MODESMALL
.STACK64
.DATADATA1_ASC DB '0649147816'
ORG 0010HDATA2_ASC DB '0072687188'
ORG 0020HDATA3_BCD DB 5DUP(?)
ORG 0028HDATA4_BCD DB 5DUP(?)
ORG 0030HDATA5_ADD DB 5DUP(?)
ORG 0040HDATA6_ASC DB 10DUP(?)
.CODEMAINPROC
FAR MOVAX,@DATA MOVDS,AX
MOVBX,OFFSETDATA1_ASC MOVDI,OFFSETDATA3_BCD MOVCX,5 CALLCONV_BCD;convertASCIItoBCD MOVBX,OFFSETDATA2_ASC MOVDI,OFFSETDATA4_BCD MOVCX,5 CALLCONV_BCD;convertASCIItoBCD CALLBCD_ADD;addtheBCDoperands MOVSI,OFFSETDATA5_ADD MOVDI,OFFSETDATA6_ASC MOVCX,05 CALLCONV_ASC ;convertresulttoASCII MOV AH,4CH INT 21H;gobacktoDOSMAINENDP;---------------;THISSUBROUTINECONVERTSASCIITOPACKEDBCDCONV_BCDPROCAGAIN:MOV AX,[BX] ;BX=pointerforASCIIdata XCHG AH,AL AND AX,0F0FH ;maskASCII3s PUSH CX ;savethecounter MOV CL,4 ;shiftAHleft4bits SHL AH,CL ;togetreadyforpacking OR AL,AH ;combinetomakepackedBCD MOV[DI],AL ;DI=pointerforBCDdata ADD BX,2 ;pointtonext2ASCIIbytes INC DI ;pointtonextBCDdata POPCX ;restoreloopcounter LOOPAGAIN RETCONV_BCDENDP;THISSUBROUTINEADDSTWOMULTIBYTEPACKEDBCDBCD_ADDPROC MOVBX,OFFSETDATA3_BCD;BX=pointerforoperand1 MOVDI,OFFSETDATA4_BCD;DI=pointerforoperand2 MOVSI,OFFSETDATA5_ADD;SI=pointerforsum MOVCX,05 CLC;CLearCarryflagBACK:MOVAL,[BX]+4;getnextbyteofoperand1 ADCAL,[DI]+4;addnextbyteofoperand2 DAA ;correctforBCDaddition MOV[SI]+4,AL ;savesum DECBX ;pointtonextbyteofoperand1 DECDI ;pointtonextbyteofoperand2 DECSI ;pointtonextbyteofsum LOOPBACK RETBCD_ADDENDP;THISSUBROUTINECONVERTSFROMPACKEDBCDTOASCIICONV_ASCPROCAGAIN2:MOVAL,[SI];SI=pointerforBCDdata MOVAH,AL;duplicatetounpackANDAX,0F00FH;unpackPUSHCX;savecounterMOVCL,04;shiftright4bitstounpackSHRAH,CL;theuppernibbleORAX,3030H;makeitASCIIXCHGAH,AL;swapforASCIIstorageconventionMOV[DI],AX;storeASCIIdataINCSI;pointtonextBCDdataADDDI,2;pointtonextASCIIdataPOPCX;restoreloopcounterLOOPAGAIN2RETCONV_ASCENDP
ENDMAIN(2)加法的非压缩BCD码调整指令AAAAAA(ASCIIAdjustafterAddition)Format:AAAFlags:AffectedAFandCFFunction:ThisinstructionisusedafteranADDinstructionhasaddedtwodigitsinASCIIcode.ThismakesitpossibletoaddASCIInumberswithoutmaskingofftheuppernibble“3”.TheresultwillbeunpackedBCDinALwithcarryflagsetifneeded.ThisinstructionadjustsonlyontheALregister.AHisincrementedifthecarryflagisset.Example: MOV AL,‘5’ ;AL=35 ADD AL,‘2’ ;addtoAL32theASCIIfor2 AAA ;changes67Hto07H OR AL,30 ;ORALwith30HtogetASCIIExample: --------- SUB AH,AH ;AH=00 MOV AL,‘7’ ;AL=37H MOV BL,‘5’ ;BL=35H ADD AL,BL ;37H+35H=6CHthereforeAL=6C AAA ;changes6CHto02inALandAH=CF=1 OR AX,3030H ;AX=3132 ----------Example:
.MODELSMALL .STACK64 ;--------------
.DATA VALUE1DB'0659478127'
ORG0010H VALUE2DB'0779563678'
ORG0020H RESULT1DB10DUP(?)
ORG0030H RESULT2DB10DUP(?) ;--------------.CODEMAINPROCFAR MOVAX, @DATA MOVDS, AX
CALLASC_ADD;callASCIIadditionsubroutine CALLCONVERT;callconverttoasciisubroutine
MOVAH,4CH INT21H;gobacktoDOSMAINENDP;---------------;THISSUBROUTINEADDSTHEASCIINUMBERSANDMAKESTHE;RESULTUNPACKED.ASC_ADDPROCCLC;clearthecarryMOVCX,10;setuploopcounterMOVBX,9;pointtoLSDBACK:MOVAL,VALUE1[BX];movenextbyteofoperand1ADCAL,VALUE2[BX];addnextbyteofoperand2AAA ;adjusttomakeitunpackedBCDMOVRESULT1[BX],AL;storeBCDsumDECBX;pointtonextbyteLOOPBACKRETASC_ADDENDP;---------------;THISSUBROUTINECONVERTSUNPACKEDBCDTOASCIICONVERTPROCMOVBX,OFFSETRESULT1;BXpointstounpackedBCDdata MOVSI,OFFSETRESULT2;SIpointstoASCIIdataMOVCX,05;CXisloopcounterBACK2:MOVAX,WORDPTR
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年度供应链合同:原材料采购与分销协议
- 2024年度北京汽车租赁市场消费趋势研究合同
- 2024年度版权质押合同:小说《海市蜃楼》的版权质押
- 2024年度民用房屋建筑施工场地占用合同
- 2024年度技术服务合同技术要求与服务范围
- 04版农田租赁合同(含农业服务)
- 2024年度充电桩设备购置与维护合同
- 04年春国家开放大学校园路灯安装及维护合同
- 电器保养合同范例
- 2024年度新能源电池研发合同
- 初三全册单词
- 透析患者失衡护理查房
- 房产背户协议
- 江苏省南师附中2023-2024高一上学期期中数学试卷及答案
- 无缝线路完整
- 识别危险源-远离危险-公开课课件
- 南平市建阳区发电有限责任公司宸前水力发电厂增效扩容改造工程环境影响报告
- 压力容器及压力管道课件
- HTML5 CSS3网页设计与制作 课件全套 吕麦丝 第1-11章 网页设计基础- CSS 中的动画与特效
- PBL教学法在临床护理教学中的应用
- 23秋国家开放大学《法律咨询与调解》形考任务1-4参考答案
评论
0/150
提交评论