Advertisement
Taigar2000

Asm_era

Oct 28th, 2020 (edited)
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. format PE GUI 4.0 ; EXE GUI-приложение для Windows
  2.  
  3. include "c:/emu8086/fasm/include/win32ax.inc" ;
  4.  
  5. .code
  6. start:
  7.  
  8.  
  9.  
  10. CALL .create_array
  11.  
  12. CALL .eratosfen
  13.  
  14. .out:
  15. cinvoke sprintf, res_str, "The number of simple numbers is %d", dword[p_count]
  16. cinvoke MessageBox,0,res_str,"Число простых чисел",MB_OK
  17.  
  18.  
  19.  
  20. .finish:
  21. cinvoke ExitProcess,0 ; выход из программы с кодом возврата 0
  22.  
  23.  
  24. .create_array:
  25. ENTER 0,0
  26. MOV eax, [n]
  27. IMUL eax, 4
  28. cinvoke malloc, eax
  29. test eax, eax
  30. JZ .alloc_error
  31. MOV [arr], eax
  32. MOV esi, eax
  33. IMUL ecx,[n], 1
  34. ADD eax, ecx
  35. .fill_arr:
  36. MOV byte[esi], 0
  37. ADD esi, 1
  38. CMP esi, eax
  39. JB .fill_arr
  40. POP ecx
  41. LEAVE
  42. RET
  43.  
  44. .alloc_error:
  45. cinvoke puts,"Error of allocating memory",0
  46. JMP .finish
  47.  
  48.  
  49.  
  50. .eratosfen:
  51. ENTER 12, 0
  52. MOV ecx, dword[n]
  53. MOV dword[ebp-8], ecx
  54. MOV ecx, dword[arr]
  55. MOV dword[ebp-4], ecx
  56. ADD dword[ebp-8], ecx
  57. INC dword[ebp-8]
  58. MOV eax, 0
  59. MOV dword[ebp-12], eax
  60. MOV esi, dword[ebp-4]
  61. MOV byte[esi], 1
  62. MOV byte[esi+1], 1
  63. MOV esi, dword[ebp-8]
  64. ADD esi, 1
  65. .start_iteration:
  66. CMP esi, dword[ebp-8]
  67. JBE .increment
  68. .next_simple:
  69. MOV esi, [ebp-4]
  70. INC dword[ebp-12]
  71. MOV eax, dword[ebp-12]
  72. ADD esi, eax
  73. CMP esi, dword[ebp-8]
  74. JG .end_eratosfen
  75. CMP byte[esi], 0
  76. JNE .next_simple
  77. ADD [p_count], 1
  78. JMP .start_iteration
  79. .increment:
  80. MOV byte[esi], 1
  81. ADD esi, dword[ebp-12]
  82. jmp .start_iteration
  83. .end_eratosfen:
  84.  
  85. LEAVE
  86. RET
  87.  
  88.  
  89.  
  90. .data
  91.  
  92. lpCommLine dd ? ; указатель на командную строку
  93. res_str db 512 dup(?) ; строка для форматированного вывода
  94. n dd 0xFFFFFFFF ; целое число (default)
  95. p_count dd 0;
  96. arr dd 0 ; Указатель на массив
  97.  
  98. ddtpt db '%*s %d',0
  99.  
  100. data import ; импортируем стандартные функции Windows
  101. library user32,'USER32.DLL', msvcrt, 'MSVCRT.DLL', \
  102. kernel32,'KERNEL32.DLL', \
  103. shell32,'SHELL32.DLL'
  104. import user32, \
  105. MessageBox, 'MessageBoxA'
  106. import kernel32, \
  107. ExitProcess,'ExitProcess', \
  108. GetCommandLine,'GetCommandLineA'
  109. import msvcrt, \
  110. sprintf, 'sprintf', sscanf, 'sscanf', printf, 'printf', scanf, 'scanf', puts, 'puts', _getch, '_getch', malloc, 'malloc', free, 'free'
  111. end data
  112.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement