prime.asm

소수 찾는 프로그램
unsigned guess;
unsigned factor;
unsigned limit;
printf("FInd primes up to:");scanf("%u,&limit);
printf("2\n");printf("3\n");
guess=5;
while(guess<=limit){
factor=3;
while(factor*factor<guess&&guess%factor1=0)factor+=2;
if(guess%factor!=0)printf("%d\n",guess);
guess+=2;
}
primes.asm
%include "asm_io.inc"
segment.data
Message db "Find primes up to:",0
segment.bss
Limit resd 1
Guess resd 1
segment.text
global _asm_main
_asm_main:
enter 0,0
pusha
mov eax, Message
call print_string
call read_int
mov [Limit],eax
mov eax,2
call print_int
call print_nl
mov dword[Guess],5
while_limit:
mov eax,[Guess]
cmp eax,[Limit]
jnbe end_while_limit
mov ebx,3
while_factor:
mov eax,ebx
mul eax
jo end_while_factor
cmp eax_while_factor
mov eax,[Guess]
mov edx,0
div ebx
cmp edx,0
je end_while_factor
add ebx,2
jmp while_factor
end_while_factor:
je end_if
mov eax,[Guess]
call print_int
call print_nl
end_if:
add dword[Guess],2
jmp while_limit
end_while_limit:
popa
mov eax,0
leave
ret