어셈 공부중, 어셈블리어로 소수찾기 코드 짜봤다.
어셈블리어라서 어려웠던 점은 딱히 없었는데..
c++에서만큼 효율적인 알고리즘은 못만들겠다.
.. 음.. 다음엔 좀 더 빠른 코드를 만들어봐야지. ㅋ..
TITLE Searching the list of primes by alleywildcat
INCLUDE Irvine32.inc
.data
primelist DWORD 2, 1000000 DUP(?)
MAXSIZE = ($ - primelist)/TYPE primelist
UPTO = 10000000 ;I'll find the primes up to UPTO number
endofindex DWORD 1
.code
main PROC
mov ebx,3 ;first, begin with number 3
$whileLoop:
cmp ebx,UPTO
jnbe $endwhile
mov edi,0
$innerloop:
cmp edi,endofindex
jnb $endinner
mov edx,0
mov eax,ebx
div primelist[edi*4]
cmp edx,0 ;if remainder is 0, then jump to noprime label
jz noprime
inc edi
jmp $innerloop
$endinner:
mov DWORD PTR primelist[edi*4],ebx ;ebx is prime
inc endofindex
noprime:
inc ebx
jmp $whileLoop
$endwhile: