资源预览内容
第1页 / 共4页
第2页 / 共4页
第3页 / 共4页
第4页 / 共4页
亲,该文档总共4页全部预览完了,如果喜欢就下载吧!
资源描述
DSEG SEGMENT count dw 0;存放素数的个数 sum dw 0;存放素数的和 sushu db 100 dup(?);存放素数 msgsushu db all of sushu are:,$;显示素数的提示信息 msgcount db 0dh,0ah,count of sushu is:,0dh,0ah,$;显示素数个数的提示信息 msgsum db 0dh,0ah,sum of sushu is:,0dh,0ah,$;显示素数和的提示信息 DSEG ENDS CSEG SEGMENT assume cs:CSEG, ds:DSEG MAIN PROC FAR ;主程序入口 call jisuan;将 100 以内素数的个数存入 COUNT 单元中,素数的和存入 SUM 单元中,并将素数存入内存自 SUSHU 开始的单元中 lea dx,msgsushu;显示素数的提示信息 mov ah,9 int 21h call dispsushu;显示素数 lea dx,msgcount;显示素数个数的提示信息 mov ah,9 int 21h call dispcount;显示素数个数 lea dx,msgsum;显示素数和的提示信息 mov ah,9 int 21h call dispsum;显示素数和mov ah,1;按任意键退出 int 21h mov ax, 4c00h ;程序结束,返回到操作系统系统 int 21h MAIN ENDP jisuan proc near mov ax, dseg mov ds, ax lea di,sushu mov bh,0 mov bl,2;求从 2 到 100 的素数、素数个数、素数的和,BL 从 2 到 100 变化 next11: cmp bl,100 ja tj mov dl,2;如果 BL 不能被 DL 从 2 到 BL-1 整除的话,则 BL 为素数 next12: cmp dl,bl jae next13 mov ax,bx div dl cmp ah,0 jz next14;整除则不是素数 inc dl jmp next12 next13: inc count;是素数,则将个数加 1 add sum,bx;是素数,则加到和中 mov di,bl;是素数,则存入相应单元中 inc di next14: inc bl jmp next11 tj:ret jisuan endp dispsushu proc near lea si,sushu mov cx,count next21: mov ax,count;每行 10 个素数 sub ax,cx mov bl,10 div bl cmp ah,0 jnz next22 mov dl,0dh;每行 10 个素数,行末加回车换行 mov ah,2 int 21h mov dl,0ah mov ah,2 int 21h next22: mov bl,si;取出一个素数 mov bh,0 call disp10;以十进制形式输出 mov dl,20h;每个素数之间加一个空格,便于区分 mov ah,2 int 21h call delay;每输出一个素数都有数秒的停顿,延时子程序 inc si loop next21 ret dispsushu endp dispcount proc near mov bx,count;取出素数个数 call disp10;以十进制形式输出 ret dispcount endp dispsum proc near mov bx,sum;取出素数的和 call disp10;以十进制形式输出 ret dispsum endp disp10 proc near;该子程序的作用是将 BX 中的数以十进制形式输出 push cx mov cx,1000d call dec_div mov cx,100d call dec_div mov cx,10d call dec_div mov cx,1d call dec_div pop cx ret dec_div proc near mov ax,bx mov dx,0 div cx mov bx,dx mov dl,al add dl,30h mov ah,2 int 21h ret dec_div endp disp10 endp delay proc near;该子程序的功能是延时 push cx push ax mov ax,60000 nextd1: mov cx,6000 nextd2: loop nextd2 dec ax jnz nextd1 pop ax pop cx ret delay endp CSEG ENDS END MAIN
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号