资源描述:
《汇编求n的阶乘.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、DATASSEGMENTstringdb"Pleaseinputanumber(0-10000):",0dh,0ahwrongstringdb"Anumberplease!",0ah,0dh,'$'inputbufferdb6,?,6dup(?)c10dw10;输入时进制转换的数ndw?;要求阶乘的数mdw?;步长cdw?;进位idw?;outputbufferdw30000dup(?);DATASENDS;*******************************************************************************STACKSSE
2、GMENT;此处输入堆栈段代码STACKSENDS;*******************************************************************************CODESSEGMENTASSUMECS:CODES,DS:DATAS,SS:STACKSSTART:MOVAX,DATAS;MOVDS,AX;;-------------------------------------------------------mainproccallinput;callfractor;movcx,diroutput:;循环输出pushcx;mo
3、vdi,cx;calloutput;popcxdeccxcmpcx,0jgeroutputdisplaylength:movdl,0dhmovah,2int21hmovdl,0ahmovah,2int21hexit:;movah,07h;int21h;movax,4c00h;INT21H;;mainendp;;-------------------------------------------------------;--------------------------------------------------------inputprocnearleabx,string
4、movcx,33disstring:movdl,[bx]movah,2int21hincbxloopdisstringjmpinputinitwronginput:leadx,wrongstringmovah,9int21hinputinit:leadx,inputbuffer;装载输入缓冲区首地址movah,0ah;输入功能代码int21h;从键盘输入一个数,以回车键结束movax,0;累加器清0movcl,inputbuffer+1;循环次数movch,0leabx,inputbuffer+2;装载字符存放区首地址inputone:;mulc10;movdl,[bx]cmpd
5、l,'0'jbwronginputcmpdl,'9'jawronginput;anddl,0fh;addal,dl;adcah,0;incbx;loopinputone;movn,axmovdl,0dhmovah,2int21hmovdl,0ahmovah,2int21h;ret;inputendp;;-----------------------------------------------------fractorprocnear;movcx,n;movi,1d;movm,0d;pushdxmovdi,0d;movax,di;movbx,2d;mulbx;movsi,axp
6、opdx;movoutputbuffer[si],1d;ctrli:;movc,0movdi,0d;ctrldi:;cmpdi,m;jbedone;jmpcmpc;done:pushdx;movax,di;movbx,2d;mulbx;movsi,axpopdx;movax,outputbuffer[si];movbx,i;mulbx;addax,c;;adcdx,0;;movbx,10000;divbx;movc,axpushdx;movax,di;movbx,2d;mulbx;movsi,axpopdx;movoutputbuffer[si],dx;incdi;jmpctrl
7、di;cmpc:;cmpc,0;jathree1;jmpnext;three1:;incm;movax,c;movoutputbuffer[si+2],ax;;next:incicmpcx,0jngif0;loopctrliif0:movdi,m;ret;;;;fractorendp;;-----------------------------------------------------outputprocnear;C2:pushdx;movax,di;movbx,2d;mu