;本程序实现加减混合运算输入格式必须为1+2-3=;程序思路:遇到一个操作符执行前一次运算,等号执行最后一次运算,然后保存本次操作符;---------提示信息------DISPLMACRODIMOVAH,9MOVDX,DIINT21HENDM;-----------DISPMACROVARMOVAH,2MOVDL,VARINT21HENDM;--------输入函数-------INPUTMACROPUSHAXPUSHBXPUSHCXPUSHDXMOVBX,0;BX存放十进制数CLCMOVDX,0NEXT0:MOVAH,1INT21HCMPAL,2BH;判断输入是否为'+'JENEXT2CMPAL,2DH;判断输入是否为'-'JENEXT2CMPAL,3DH;判断‘=’JENEXT2SUBAL,30HJLNEXT1CMPAL,9JGNEXT1MOVAH,0;将输入的数转换成10进制数XCHGAX,BXMOVCX,10MULCXADDAX,BXJCNEXT1XCHGAX,BXJMPNEXT0NEXT1:MOVDX,0MOVBX,0MOVDI,OFFSETSTR;提示出错DISPLDIMOVDI,OFFSETSTR2DISPLDIJMPNEXT0NEXT2:CMPDX,0JNZNEXT1CMPCOUNT,1;第一次输入存到buf0以后输入全部存放到buf1JEL0MOVBUF0,BXJMPL1L0:MOVBUF1,BXJMPNEXT3L1:MOVOPER,AL;将操作符保存至operMOVCOUNT,1MOVBX,0JMPNEXT0NEXT3:CMPOPER,'+';判读那是何种操作JEN0CMPOPER,'-'JEN1N0:MOVBX,BUF0;加法相应操作ADDBX,BUF1MOVBUF0,BXCMPAL,'='JENEXT4JMPL1N1:MOVDX,BUF0;加法操作CMPFLAG,1;如果原来buf0里的数是负数用buf1-buf0的绝对值JNEN2XCHGDX,BUF1MOVFLAG,0N2:CLCSBBDX,BUF1JNCN3MOVFLAG,1NEGDX;如果相减为负数则存放绝对值N3:MOVBUF0,DXCMPAL,'='JENEXT4JMPL1NEXT4:CMPFLAG,1JNENEXT5DISP'-';若果结果为负数输出负号NEXT5:CALLPRINTPOPDXPOPCXPOPBXPOPAXENDMDATASSEGMENTSTRDB0AH,0DH,'$'STR0DB'pleaseinputarithmeticexpressions:',0AH,0DH,'$'STR2DB'thenumisunexpected,inputagain:',0AH,0DH,'$'BUF0DW?BUF1DW?FLAGDB0OPERDB?COUNTDB0DATASENDSSTACKSSEGMENTDW256DUP(?);此处输入堆栈段代码STACKSENDSCODESSEGMENTASSUMECS:CODES,DS:DATAS,SS:STACKSSTART:MOVAX,DATASMOVDS,AXMOVDI,OFFSETSTR0DISPLDIINPUTMOVAH,4CHINT21H;-----------显示函数--------PRINTPROCNEARPUSHAXPUSHBXPUSHCXPUSHDXMOVCX,0;记录有效数字位数MOVBX,10;除10取余MOVAX,BUF0LAST:MOVDX,0DIVBXPUSHDXINCCXCMPAX,0JNZLASTAGE:POPDX;出栈输出ORDX,30HMOVAH,2INT21HLOOPAGEPOPDXPOPCXPOPBXPOPAXRETPRINTENDPCODESENDSENDSTARTDISPMACROVARMOVAH,2MOVDL,VARINT21HENDMDATASSEGMENTDATA0DB'PLEASEINPUTANUMBER(0-999):','$'DATA1DB'overflowinputagain:','$'DATA2DB'PLEASEINPUTANOTHERNUMBER(EXP:123)','$'DATA3DB'PLEASEINPUTANOPREATOR:','$'DATA4DB'THEOPERATORISWRONG,INPUTAGAIN:','$'OPERDB?FLAGDB0FLAG1DB0DATADW3DUP(?)DATASENDSSTACKSSEGMENTDW256DUP(?)STACKSENDSCODESSEGMENTASSUMECS:CODES,DS:DATAS,SS:STACKSSTART:MOVAX,DATASMOVDS,AXMOVDI,OFFSETDATA0;提示信息CALLDISPLMOVSI,0;SI作为数组下标CALLINPUTCALLNEWLINEMOVDI,OFFSETDATA3;提示信息CALLDISPLAGAIN:MOVAH,1;1号功能输入四则运算符INT21HCMPAL,'+';判断输入的是不是+,-,*,/JENEXT0CMPAL,'-'JENEXT0CMPAL,'*'JENEXT0CMPAL,'/'JENEXT0CALLNEWLINE;输入的运算符不合法,重新输入MOVDI,OFFSETDATA4CALLDISPLJMPAGAINNEXT0:MOVOPER,AL;保存运算符CALLNEWLINEMOVDI,OFFSETDATA2;输入第二个操作数CALLDISPLMOVSI,2CALLINPUTMOVAX,DATA[0]MOVBX,DATA[2]CMPOPER,'+';判断是那种操作,进行运算JENEXT1CMPOPER,'-'JENEXT2CMPOPER,'*'JENEXT3CMPOPER,'/'JENEXT4NEXT1:;加法运算CLCADCAX,BXJNCN1MOVFLAG,1;判断是否进位N1:MOVDATA[4],AX;运算结果放入内存JMPOUTPUTNEXT2:;减法运算CLCSBBAX,BXJNCN2MOVFLAG,1;判断是否借位NEGAXN2:MOVDATA[4],AX;运算结果放入内存JMPOUTPUTNEXT3:;乘法运算CLCMOVDX,0MULBXMOVDATA[4],AX;运算结果放入内存JMPOUTPUTNEXT4:;除法运算CLCMOVDX,0CMPBX,0JNZN4;判断除数是否为0CALLNEWLINECALLERRORCALLNEWLINEMOVDI,OFFSETDATA2CALLDISPLMOVSI,2CALLINPUTJMPNEXT4N4:DIVBXMOVDATA[4],AX;运算结果放入内存OUTPUT:CALLNEWLINEMOVDI,0;输出第一个操作数CALLPRINTDISPOPER;输出运算符MOVDI,2CALLPRINT;输出第二个操作数DISP'='CMPFLAG,1JNZNEXT5DISP'-'NEXT5:MOVDI,4CALLPRINT;输出结果MOVAH,4CHINT21H;-----------输入函数------------INPUTPROCNEARPUSHAXPUSHBXPUSHCXPUSHDXMOVBX,0;BX存放十进制数CLCMOVDX,0L0:;----------输入数字----------MOVAH,1;判断数字是否合法INT21HCMPAL,0DHJEL2SUBAL,30HJLL1CMPAL,9JGL1;---------转换成十进制数-------MOVAH,0;转换成10进制数放入内存XCHGAX,BXMOVCX,10MULCXADDAX,BXJCL1XCHGAX,BXJMPL0L1:MOVDX,0MOVBX,0CALLNEWLINECALLERRORJMPL0L2:CMPDX,0JNZL1MOVDATA[SI],BXMOVDX,0POPDXPOPCXPOPBXPOPAXRETINPUTENDP;--------------提示信息------------DISPLPROCNEARMOVAH,9MOVDX,DIINT21HRETDISPLENDP;-------回车换行--------NEWLINEPROCNEARPUSHAXPUSHDXMOVDL,0AHMOVAH,2INT21HMOVDL,0DHMOVAH,2INT21HPOPDXPOPAXRETNEWLINEENDP;----------错误提示----------------ERRORPROCNEARPUSHAXPUSHDXMOVDX,OFFSETDATA1MOVAH,9INT21HPOPDXPOPAXRETERRORENDP;-----------显示函数--------PRINTPROCNEARPUSHAXPUSHBXPUSHCXPUSHDXMOVCX,0MOVBX,10MOVAX,DATA[DI]LAST:MOVDX,0;除10压栈DIVBXPUSHDXINCCXCMPAX,0JNZLASTAGE:POPDX;出栈输出ORDX,30HMOVAH,2INT21HLOOPAGEPOPDXPOPCXPOPBXPOPAXRETPRINTENDPCODESENDSENDSTART