Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- format PE GUI 4.0 ; EXE GUI-приложение для Windows
- include "c:/emu8086/fasm/include/win32ax.inc" ;
- .code
- start:
- CALL .create_array
- CALL .eratosfen
- .out:
- cinvoke sprintf, res_str, "The number of simple numbers is %d", dword[p_count]
- cinvoke MessageBox,0,res_str,"Число простых чисел",MB_OK
- .finish:
- cinvoke ExitProcess,0 ; выход из программы с кодом возврата 0
- .create_array:
- ENTER 0,0
- MOV eax, [n]
- IMUL eax, 4
- cinvoke malloc, eax
- test eax, eax
- JZ .alloc_error
- MOV [arr], eax
- MOV esi, eax
- IMUL ecx,[n], 1
- ADD eax, ecx
- .fill_arr:
- MOV byte[esi], 0
- ADD esi, 1
- CMP esi, eax
- JB .fill_arr
- POP ecx
- LEAVE
- RET
- .alloc_error:
- cinvoke puts,"Error of allocating memory",0
- JMP .finish
- .eratosfen:
- ENTER 12, 0
- MOV ecx, dword[n]
- MOV dword[ebp-8], ecx
- MOV ecx, dword[arr]
- MOV dword[ebp-4], ecx
- ADD dword[ebp-8], ecx
- INC dword[ebp-8]
- MOV eax, 0
- MOV dword[ebp-12], eax
- MOV esi, dword[ebp-4]
- MOV byte[esi], 1
- MOV byte[esi+1], 1
- MOV esi, dword[ebp-8]
- ADD esi, 1
- .start_iteration:
- CMP esi, dword[ebp-8]
- JBE .increment
- .next_simple:
- MOV esi, [ebp-4]
- INC dword[ebp-12]
- MOV eax, dword[ebp-12]
- ADD esi, eax
- CMP esi, dword[ebp-8]
- JG .end_eratosfen
- CMP byte[esi], 0
- JNE .next_simple
- ADD [p_count], 1
- JMP .start_iteration
- .increment:
- MOV byte[esi], 1
- ADD esi, dword[ebp-12]
- jmp .start_iteration
- .end_eratosfen:
- LEAVE
- RET
- .data
- lpCommLine dd ? ; указатель на командную строку
- res_str db 512 dup(?) ; строка для форматированного вывода
- n dd 0xFFFFFFFF ; целое число (default)
- p_count dd 0;
- arr dd 0 ; Указатель на массив
- ddtpt db '%*s %d',0
- data import ; импортируем стандартные функции Windows
- library user32,'USER32.DLL', msvcrt, 'MSVCRT.DLL', \
- kernel32,'KERNEL32.DLL', \
- shell32,'SHELL32.DLL'
- import user32, \
- MessageBox, 'MessageBoxA'
- import kernel32, \
- ExitProcess,'ExitProcess', \
- GetCommandLine,'GetCommandLineA'
- import msvcrt, \
- sprintf, 'sprintf', sscanf, 'sscanf', printf, 'printf', scanf, 'scanf', puts, 'puts', _getch, '_getch', malloc, 'malloc', free, 'free'
- end data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement