随机产生一系列的ascii码字符,将其分类输出
;
本程序功能是实现:随机产生一系列的ascii码字符,将其分类输出
DATAS SEGMENT ;此处输入数据段代码Str1db'Please input a number:','$'Str2db'output the number:','$'Str3db'output the capital word:','$'Str4db'output the small word:','$'Str5db'output the other:','$'StrEnterdb 0dh,0ah,'$'Bufdb5 dup(?);DecBufdb5 dup(?)NUdb 100 dup(?)CDdb 1000 dup(?)SDdb 1000 dup(?)OTHERdb 1000 dup(?)Numdw0Adw0 countNu dw 0countCD dw 0countSD dw 0countOt dw 0 DATAS ENDSSTACKS SEGMENT ;此处输入堆栈段代码STACKS ENDSCODES SEGMENT ASSUME CS:CODES,DS:DATAS,SS:STACKSSTART: MOV AX,DATAS MOV DS,AX ;此处输入代码段代码 lea dx,Str1;显示提示:输入要产生随机数的个数movah,9int21hmovcx,5;输入数值部分,最大输入5位的数call EnterNlea dx,strEnter mov ah,9 int 21h ;将键盘输入的数转化为数值 lea si,Buf mov ax,0 ;mov Num,0 mov A,0 mov cx,Numlpout: mov ax,A mov bx,10mul bx;sub ax,0030hmov A,axmov al,[si]mov ah,0sub al,30hadd A,axinc siloop lpoutlea si,CDlea di,SDlea bp,OTHERlea bx,NUmov cx,A;随机数产生函数rand: xor al,al;异或运算 out 43h,al;I/O端口输出语法: OUT {端口号│DX},累加器 in al,40h;I/O端口输入语法: IN 累加器, {端口号│DX} cmp al,126;比较.(两操数作减法,仅修改标志位,不回送结果). ja rand xor ah,ah;异或运算 call Sort ;mov dl,20h;加了这句代码,经测试,发现数据更离散,否则不离散,比较郁闷mov dl,al mov ah,2 int 21h loop rand lea dx,strEnter mov ah,9 int 21h lea dx,Str2;显示提示:输 的个数movah,9int21hmov cx,countNucmp cx,0;判断是否为零为零则不输出jz lpCDlea si,NUoutNu:mov dx,[si]mov ah,2int 21h;inc siloop outNulpCD:lea dx,strEnter mov ah,9 int 21h lea dx,Str3;显示提示:输 的个数movah,9int21h;显示大写字母个数的,用来调试时用;mov dx,countCD;add dx,0030h;mov ah,2;int 21h;mov cx,countCDlea si,CDoutCD:mov dx,[si]mov ah,2int 21hinc siloop outCDlea dx,strEnter mov ah,9 int 21h lea dx,Str4;显示提示:输 的个数movah,9int21h;显示小写字母个数的,用来调试时用;mov dx,countSD;add dx,0030h;mov ah,2;int 21hmov cx,countSDlea si,SDoutlp:mov dx,[si]mov ah,2int 21hinc siloop outlplea dx,strEnter mov ah,9 int 21hlea dx,Str5;显示提示:输 的个数movah,9int21h;显示其他字符个数的,用来调试时用;mov dx,countOt;add dx,0030h;mov ah,2;int 21h;mov cx,countOtlea si,OTHERoutOt:mov dx,[si]mov ah,2int 21hinc siloop outOtlea dx,strEnter mov ah,9 int 21h jmp code_exit;函数Sort PROC;PUSH AXPUSH BXPUSH CXPUSH DXCMP AL,'0'jb lpotherlpnum:cmp al,'9'ja lpBwordmov [bx],alinc bxinc countNujmp sort_exitlpBword:cmp al,41hjb lpothercmp al,5ahja lpSwordmov [si],alinc siinc countCDjmp sort_exitlpSword:cmp ax,61hjb lpothercmp ax,7ahja lpothermov [di],alinc diinc countSDjmp sort_exitlpother:mov [BP],alinc BPinc countOt;jmp sort_exitsort_exit:POP DXPOP CXPOP BX;POP AXRETSort ENDP ;函数的传值:CX:输入数的位数,EnterN PROC PUSH DX PUSH BX PUSH AXlea si,Buf;输入数值部分,最大输入5位的数lp1:movah,7int21hcmpal,0dhjzlp_ex;只能输入0-9之间的数cmpal,'0'jb lp1cmpal,'9'ja lp1;每次输入的数都存入buf中mov [si],alinc siinc Nummovah,2movdl,alint 21hloop lp1lp_ex: POP AX POP BX POP DX RETEnterN ENDP code_exit: MOV AH,4CH INT 21HCODES ENDS END START