www.pudn.com > Demo_asm_80x86.rar > Prime2.asm


;****************************************************** 
;* 文件名:Prime2.asm 
;* 创建日期:2001.7.2 
;* 作者:陈文尧 
;* 功能:打印素数 
;* 备注:本程序是Prime.asm的修订版本 
;****************************************************** 
include system.inc 
 
;****************************************************** 
;* 以下代码由汇编专家产生,不要随便修改 
;****************************************************** 
.CODE 
	ifdef __COM__ 
		org	100h 
	endif 
@@Start: 
;------------------------------------------------------ 
; 初始化数据段 
;------------------------------------------------------ 
	InitDS	cs 
;------------------------------------------------------ 
; 调用主函数 
;------------------------------------------------------ 
	call	main 
;------------------------------------------------------ 
; 正常返回DOS 
;------------------------------------------------------ 
	ReturnDos 
 
;++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
;+ 主函数,加入实现程序功能的代码 
;++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
main	proc 
	DisplayMessage	msg1 
@GetNumber: 
	LibCall		GetLong ;结果在dx:ax或eax 
	or			eax,eax 
	jg			short @Continue 
	DisplayMessage	msg2 
	jmp			@GetNumber 
@Continue: 
	mov			edi,eax 
      LibCall		PutLong,dx,ax 
	DisplayMessage	msg3 
	sub			esi,esi 
	sub			ch,ch 
@Outer: 
	inc			esi 
	call			Limit 
	cmp			ebp,00000001h 
	jg			short @Skip 
	cmp			esi,ebp 
	jz			short @Outer@End 
	jmp			short @Print 
@Skip: 
	sub			ebx,ebx 
	inc			ebx 
@Inner: 
	inc			ebx 
	mov			eax,esi 
	sub			edx,edx 
	div			ebx 
	or			edx,edx 
	jz			short @Outer@End 
      cmp			ebx,ebp 
      jb			@Inner 
@Print: 
      inc			ch 
      and			ch,07h 
      jnz			short @Skip@Crlf 
      inc			ch 
      push			cx 
      LibCall		Crlf 
      pop			cx 
@Skip@Crlf: 
      mov			eax,esi 
      shr			eax,10h 
      push			cx 
      LibCall		PutLongEx,ax,si,11d,10d 
      pop			cx 
@Outer@End: 
	cmp			esi,edi 
	jb			@Outer 
	; 
	ret 
main	endp 
 
Limit proc near 
      sub		cl,cl 
      mov		eax,esi 
      mov		ebp,eax 
@Limit@Begin: 
      shr		eax,01h 
      jz		short @Limit@End 
      inc		cl 
      jmp		@Limit@Begin 
@Limit@End: 
      cmp		cl,01h 
      jz		short @Limit@Skip 
      shr		cl,01h 
@Limit@Skip: 
      shr		ebp,cl 
      ; 
      ret 
Limit endp 
 
msg1	db	'求n(n为正整数)以内的素数,请输入n值:$' 
msg2	db	'输入的n值不合格,请重新输入:$' 
msg3	db	'以内的素数有:',0dh,0ah,'$' 
;****************************************************** 
;* 标志程序结束并指定程序入口 
;****************************************************** 
	end	@@Start