加减法参考程序DATASEGMENTPARAPUBLIC‘DATA’DATAENDSSTACKSEGMENTPARASTACK‘STACK’DB512DUP(?)STACKENDSCODESEGMENTPARAPUBLIC‘CODE’ASSUMECS:CODE,DS:DATA,ES:DATA,SS:STACKSTARTPROCFARPUSHDSMOVAX,0PUSHAXMOVAX,DATAMOVDS,AXMOVES,AXMOVAX,0000MOVDX,0000MOVSI,2050HMOVDI,2150HMOVBP,2250HMOVWORDPTR[SI],0205HMOVWORDPTR[DI],0408HMOVWORDPTR[BP],0109HMOVAL,…;送被加数低8位AL=…;低8位相加AL=,AH=,CF=…;加法ASCII调整AL=,AH=,CF=MOVDL,AL;DL=MOVAL,[SI+1];AL=…;带进位加;AL=,CF=…;加法ASCII调整AL=,AH=,CF=…;AL与DL交换AL=,DL=…;和的低8位减减数的低8位AL=…;减法ASCII调整AL=,AH=,CF=…;AL与DL交换,存低8位结果AL=,DL=…;高8位带进位减AL=…;减法ASCII调整AL=,AH=,CF=MOVDH,AL;DH=RETSTARTENDPCODEENDSENDSTART16进制到ACII码参考程序nameHEXASCdatasegmentparapublic'data'hexdw0A5E9hascdb20dup(0)dataendsstacksegmentparastack'stack'db512dup(?)stackendscodesegmentparapublic'code'assumecs:code,ds:data,es:data,ss:stackstartprocfarpushdsmovax,0pushaxmovax,datamovds,axmoves,axmovcx,0004hmovax,…;AX=,取十六进制数0ebf9hleabx,ascaa:pushcx…;给循环计数器赋转换代码长度…;AX=,十六进制数循环左移pushaxandax,000fh;AX=;AX=AX=;AX=cmpal,…;判别是否为“0~9”…ascii;是“0~9”转asciiaddal,07hascii:addal,30h;al=;al=al=;al=popaxpopcxloopaaretstartendpcodeendsendstartACII码到BCD码参考程序NAMEASCBCDDATASEGMENTPARAPUBLIC'DATA'ORG0150HDATA1DW3538H,4237H,3946H,3639H,3642HORG0160HDB10DUP(?)DATAENDSSTACKSEGMENTPARASTACK'STACK'DB512DUP(?)STACKENDSCODESEGMENTPARAPUBLIC'CODE'ASSUMECS:CODE,DS:DATA,ES:DATA,SS:STACKSTARTPROCFARPUSHDSMOVAX,0PUSHAXMOVAX,DATAMOVDS,AXMOVES,AXMOVCX,05H…;DI=,[DI]=…….ASCII首址送DI…;SI=,BCD首址送SIBB:MOVBL,0FFHMOVAL,[DI];AL=…;检查是否为大于9的ASCII码…;是转DONE…;AL=,[DI]=不是,取ASCII码低4位…;小于0的十进制数,转DONEMOVBL,ALDONE:MOVAL,BL;AL=,[DI]=MOV[SI],AL;[SI]=…;指针加1…;指针加1…;(CX)不为0,转BBRET[160H]=.......STARTENDPCODEENDSENDSTARTBCD码→二进制参考程序NAMEBCD2DATASEGMENTORG0180HDAT1DW0802H,0103H,0009H,0706H,0407HORG0190HDAT2DB10DUP(?)DATAENDSSTACKSEGMENTPARASTACK'STACK'DB512DUP(?)STACKENDSCODESEGMENTASSUMECS:CODE,DS:DATA,ES:DATA,SS:STACKSTARTPROCFARPUSHDSMOVAX,0PUSHAXMOVAX,DATAMOVDS,AXMOVES,AX…;循环计数器赋转换代码长度…;BCD码首址送DI…;二进制首址送SIXL:…;BCD码十位数值赋ALMOVBL,0AHMULBL;乘10INCDIMOVAH,00H…;BCD码十位和个位相加,转换结束…;转换结果存二进制起始地址INCDIINCDIINCSI;(CX)不为0转AALOOPXLRETSTARTENDPCODEENDSENDSTART查表处理参考程序DATASEGMENTLISTDW12,11H,22H,33H,44H,55H,66H,77H,88H,99H,111H,222H,333HDATAENDSCODESEGMENTDEL_ULPROCFARASSUMECS:CODE,DS:DATA,ES:DATAMAIN:PUSHDSSUBAX,AXPUSHAXMOVAX,DATAMOVDS,AXMOVES,AXMOVAX,…..;AX=CLDLEADI,…;DI=,[DI]=…..…取得数据区首地址PUSHDIMOVCX,ES:[DI];CX=ADDDI,2…SCASW;AX=,DI=,[DI-2]=字符串比较…DELETE;字符相同转移JMPSHORTEXITDELETE:…DEC_CNT;CX寄存器内容为0则到数据区尾转结束NEXT_EL:MOVBX,ES:[DI];BX=,[DI-2]MOVES:[DI-2],BX;(DI-2)=,(DI)=ADDDI,2LOOPNEXT_ELDEC_CNT:POPDIDECWORDPTRES:[DI];(0H)=……….EXIT:RETDEL_ULENDPCODEENDSENDMAIN分支与循环参考程序DATASEGMENTORG200HARRAYDW56H,12H,-6790H,0,78H,0H,-1H,0H,3000H,90HDATAENDSCODESEGMENTMAINPROCFARASSUMECS:CODE,DS:DATASTART:PUSHDSMOVAX,0PUSHAXMOVAX,DATAMOVDS,AXMOVCX,…;CX=循环计数器赋转换代码长度MOVBX,0;[0200H]=MOVDI,BXMOVSI,BX…;BX=……字数组首址送BXAGAIN:MOVAX,[BX]…;与0比较…LEQ;小于或等于0转INCDI;AX=,DI=JMPSHORTNEXTLEQ:…NEXT;小于0转INCSI;AX=,SI=NEXT:ADDBX,2LOOPAGAINMOVAX,10DI=,SI=…;字数组长度减负数…;AX=字数组长度减负数再减零RETMAINENDPCODEENDSENDSTART排序参考程序DATASEGMENTDATDW10,1234H,2345H,3456H,9999HDW8700H,7000H,0,6500H,5111H,4FBDHDATAENDSCODESEGMENTMAINPROCFARASSUMECS:CODE,DS:DATA,ES:DATASTART:PUSHDS;初始化SUBAX,AXPUSHAXMOVAX,DATAMOVDS,AXMOVES,AX…;字数组首地址送DI…;循环长度送CX…;循环长度减1(10个数据,循环9次)LOOP1:MOVSI,CXINCDIINCDILOOP2:…;取DAT(I)个数据…;与DAT(I+1)个数据比较…;如果DAT(I+1)大于或等于DAT(I)转移…;AX=,(DI)=否则交换…;(DI)=存较小的数CON:ADDDI,2LOOPLOOP2…;(DI)=…….取循环长度,准备下次比较…;字数组首地址送DILOOPLOOP1;(DI)=……..RETMAINENDPCODEENDSENDSTART6264参考程序.486DATASEGMENTAT0USE16ORG4000HDATA1DB6DUP(?)DATAENDSCODESEGMENTUSE16ASSUMECS:CODE,DS:DATA,ES:DATAORG2000HBEG:JMPSTARTSTART:MOVAX,DATAMOVDS,AXMOVES,AXMOVAX,0MOVSS,AXMOVSP,1000HMOVAX,…;6264段地址MOVDS,AX;DS=XORAX,AXMOVBX,…;BX=偏移地址MOVCX,…;数据长度M1:MOVBYTEPTR[BX],AL;(BX)=,(BX)=,(BX)=送数据INCALINCBXLOOPM1HARTENDPCODEENDSENDBEG8255参考程序.486DATASEGMENTAT0USE16PORTAEQU…;A口PORTBEQU…;B口PORTCEQU…;C口CONTROLEQU20FH;控制口PORT1EQU340H;七段码段地址PORT2EQU360H;七段码位地址ORG…HDATA1DB6DUP(?);输入数据区ORG…HDATA2DB6DUP(?);显示缓冲区DATAENDSCODESEGMENTUSE16ASSUMECS:CODE,DS:DATA,ES:DATAORG2000HBEG:JMPSTARTTABDB3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FHDB67H,77H,7CH,39H,5EH,79H,71H;段码表STlART:MOVAX,DATA;初始化MOVDS,AXMOVES,AXMOVAX,0MOVSS,AXMOVSP,1000H…;8255初始化……;清显示…LP:…;AL=读数据……;存数据…CALLCZ;调用拆字子程序CALLDISP;调用显示子程序JMP…;循环取数显示CZPROCPUSHCXLEASI,DATA1;SI=拆字,取数LEADI,DATA2;DI=显示缓冲区首址CZ0:MOVBL,[SI]ANDBL,0F0H;BL=MOVCL,4ROLBL,CLMOV[DI],BL;(DI)=INCDIMOVBL,[SI]ANDBL,0FH;BL=MOV[DI],BLINCSIINCDICMPSI,…HJBECZ0POPCXRETCZENDPDISPPROC;显示子程序PUSHCXPUSHDXLEABX,TABLEASI,DATA2MOVAH,0C1HDISP1:MOVDX,PORT2MOVAL,AHOUTDX,AL;AL=,AL=位输出MOVDX,PORT1MOVAL,[SI]XLATOUTDX,AL;AL=,AL=段输出MOVCX,0200HLOOP$INCSISALAH,1ORAH,0C0HCMPAH,0C0HJNZDISP1POPDXPOPCXRETDISPENDPCODEENDSENDBEG8253参考程序.486DATASEGMENTAT0USE16ZDXLEQU20H;中断向量(20H)OPORTEQU3A0H;8259偶地址JPORTEQU3A8H;8259奇地址PORT1EQU340H;段地址PORT2EQU360H;位地址DS0EQU300H;8253通道0DSCEQU30CH;8253控制口COUNTEQU50ORG4000HDATA1DB6DUP(?)ORG4040HDATA2DB3DUP(?)DATAENDSCODESEGMENTUSE16ASSUMECS:CODE,DS:DATA,ES:DATAORG2000HBEG:CLIJMPSTARTTABDB3FH,06H,5BH,4FH,66H,6DH,7DH,07H,DB7FH,67H,77H,7CH,39H,5EH,79H,71H;段码表TIMERD