首页
论坛
专栏
课程

[原创]prime.asm

2010-7-15 17:11 4041

[原创]prime.asm

2010-7-15 17:11
4041
;以16进制数显示4294967295以内的素数。
;本文改编自我的一个vbs脚本。脚本附后。
;made by correy
;QQ:112426112
;Email:leguanyuan@126.com
;Homepage:http://correy.webs.com
;不足之处,敬请指导。
;如本文的编码极不规范,但还算能实现了。
.386
.model flat,stdcall
option casemap:none
include windows.inc
include kernel32.inc
includelib kernel32.lib

.data
two db "00000002",0
entry db 13,10,0

.data?
buffer db 256 DUP (?)
bufferl db 8 dup (?)
hstdin dd ?
hstdout dd ?

.code

showeax proc;坚决拒绝使用wsprintf等类似函数。
pushad
mov ecx,8
xor esi,esi
againp:
dec ecx
rol eax,4
push eax
and eax,0Fh
cmp eax,9
jg big
add eax,30h
mov [bufferl+esi],al
pop eax
inc esi
cmp ecx,0
jne againp
je showp
big:
add eax,37h
mov [bufferl+esi],al
pop eax
inc esi
cmp ecx,0
jne againp
showp:
popad
ret
showeax endp

prime proc ;eax是要辨认的素数。
pushad
cmp eax,1
je exit

cmp eax,2
je exit2

mov esi,eax

mov ebx,2

mov ecx,eax

divit:
xor edx,edx
mov eax,esi
div ebx
cmp edx,0
je exit
inc ebx
cmp ebx,esi
je show
jmp divit

show:
mov eax,esi
call showeax
invoke WriteFile,hstdout,addr bufferl,8,0,0
invoke WriteFile,hstdout,addr entry,2,0,0
popad
ret

exit2:invoke WriteFile,hstdout,addr two,8,0,0;显示数字2
invoke WriteFile,hstdout,addr entry,2,0,0
exit:
popad
ret
prime endp

start:

invoke GetStdHandle,-10
mov hstdin,eax
invoke GetStdHandle,-11
mov hstdout,eax

mov ecx,-1
mov eax,2
again:
push eax
call prime
pop eax
inc eax
loop again

invoke ExitProcess,0
end start
;made at 2010.07.09
'素数(也叫质数,我叫他光棍数或独身数)的算法。
'made by correy
'QQ:112426112
'Email:leguanyuan@126.com
'Homepage:http://correy.webs.com
'不足之处,敬请指导。
for n = 1 to 10000 '显示10000以内的素数。
call prime (n)
next

function prime(x) '是否是素数。

if x=1 then
exit function
end if

if x = 2 then
wscript.echo x
exit function
end if

y = x

for counter = 2 to y-1

z = x mod counter

if z = 0 then
exit function
end if

next

wscript.echo x

end function
'made at 2010.07.09

[公告]安全测试和项目外包请将项目需求发到看雪企服平台:https://qifu.kanxue.com

上传的附件:
最新回复 (1)
lsmjj 2010-7-15 17:38
2
0
收藏了 呵呵
游客
登录 | 注册 方可回帖
返回