ionutHulub

prime numbers in ASM

Jan 23rd, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. int main() {
  4.     _asm{
  5.         sub esp, 4
  6.         mov [esp], '%'
  7.         mov [esp + 1], 'd'
  8.         mov [esp + 2], '\t'
  9.         mov [esp + 3], '\0'
  10.         mov ebx, 1000
  11.         mov ecx, 1
  12.         jmp start_while1
  13. incrementare1:
  14.         add ecx, 1
  15. start_while1:
  16.         cmp ecx, ebx
  17.         jge end_while1
  18.         mov edi, 2
  19.         mov esi, 0
  20.         jmp start_while2
  21. incrementare2:
  22.         add edi, 1
  23. start_while2:
  24.         cmp edi, ecx
  25.         jge end_while2
  26.         mov eax, ecx
  27.         xor edx, edx
  28.         div edi
  29.         test edx, edx
  30.         jnz incrementare2
  31.         mov esi, 1
  32. end_while2:
  33.         test esi, esi
  34.         jnz incrementare1
  35.         push ecx
  36.         lea ecx, [esp+4]
  37.         push ecx
  38.         call printf
  39.         pop ecx
  40.         pop ecx
  41.         jmp incrementare1
  42. end_while1:
  43.         add esp, 4
  44.     }
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment