Advertisement
varden

Untitled

Dec 22nd, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .486
  2. .model flat, stdcall
  3.  option casemap: none
  4.  include windows.inc
  5.  
  6. .code
  7.  
  8. DllEntry PROC hINSTDLL:HINSTANCE, reason:DWORD, reserved1:DWORD
  9.         mov eax, TRUE
  10.         ret
  11. DllEntry ENDP
  12.  
  13. PreSieveAtkinAsm proc stdcall sieve: PTR, limit: DWORD, x: DWORD, root: DWORD
  14.  
  15.     mov esi, sieve
  16.     mov ebx, 0
  17.  
  18. mainloop:
  19.     inc ebx ;increment y
  20.     cmp ebx, root ;compare root with y
  21.     jg mainloopend  ;y <= root
  22.    
  23.     ;n - eax
  24.     ;y - ebx
  25.     ;n = (4*x*x)+(y*y)
  26.  
  27. part1:
  28.     mov eax, x ;x
  29.     mul eax ;x*x
  30.     mov ecx, 4
  31.     mul ecx ;4*x*x
  32.     mov ecx, eax ;4*x*x in ecx
  33.     mov eax, ebx ;y
  34.     mul eax ;y*y
  35.     add eax, ecx ;4*x*x+y*y in eax
  36.  
  37.     cmp eax, limit
  38.     jle part2
  39.  
  40.     push eax ;push n to stack
  41.    
  42.     mov ecx, 12
  43.     div ecx
  44.     pop eax ;pop n from stack
  45.     mov eax, 1
  46.     cmp eax, edx
  47.     je xor1 ;n
  48.     mov eax, 5
  49.     cmp eax, edx
  50.     je xor1
  51.     jmp part2
  52.  
  53.     ;n in eax
  54.  
  55. xor1:
  56.     not BOOL PTR [esi + 1 * eax]
  57.  
  58. part2:
  59.     ;n - eax
  60.     ;y - ebx
  61.     ;n = (3*x*x)+(y*y)
  62.  
  63.     mov eax, x ;x
  64.     mul eax ;x*x
  65.     mov ecx, 3
  66.     mul ecx ;4*x*x
  67.     mov ecx, eax ;4*x*x in ecx
  68.     mov eax, ebx ;y
  69.     mul eax ;y*y
  70.     add eax, ecx ;4*x*x+y*y in eax
  71.  
  72.     cmp eax, limit
  73.     jle part3
  74.  
  75.     push eax ;push n to stack
  76.    
  77.     mov ecx, 12
  78.     div ecx
  79.     pop eax ;pop n from stack
  80.     mov eax, 7
  81.     cmp eax, edx
  82.     je xor2 ;n
  83.     jmp part3
  84.  
  85.     ;n in eax
  86.  
  87. xor2:
  88.     not BOOL PTR [esi + 1 * eax]
  89.  
  90. part3:
  91.     ;n - eax
  92.     ;y - ebx
  93.     ;n = (4*x*x)-(y*y)
  94.     cmp x, ebx
  95.     jle mainloop
  96.    
  97.     mov eax, x ;x
  98.     mul eax ;x*x
  99.     mov ecx, 4
  100.     mul ecx ;3*x*x
  101.     mov ecx, eax ;3*x*x in ecx
  102.     mov eax, ebx ;y
  103.     mul eax ;y*y
  104.     sub eax,ecx ;4*x*x-y*y in eax
  105.  
  106.     cmp eax, limit
  107.     jle mainloop
  108.  
  109.     push eax ;push n to stack
  110.    
  111.     mov ecx, 12
  112.     div ecx
  113.     pop eax ;pop n from stack
  114.     mov ecx, 11
  115.     cmp ecx, edx
  116.     je xor3
  117.     jmp mainloop
  118.  
  119.     ;n in eax
  120.  
  121. xor3:
  122.     not BOOL PTR [esi + 1 * eax]
  123.    
  124. mainloopend:
  125.     leave
  126.     ret
  127.  
  128. PreSieveAtkinAsm endp
  129.  
  130. END DllEntry
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement