Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- format PE console
- entry start
- include 'win32a.inc'
- section '.data' data readable writeable
- array dd 5, 2, 9, 3, 1 ; пример массива для сортировки
- array_size equ ($ - array) / 4
- buffer db 'Sorted array: ', 0
- section '.code' code readable executable
- start:
- mov ecx, array_size
- outer_loop:
- mov edx, 0
- mov ebx, ecx
- dec ebx
- inner_loop:
- mov eax, [array + edx * 4]
- cmp eax, [array + edx * 4 + 4]
- jbe not_swap
- mov eax, [array + edx * 4]
- mov ebx, [array + edx * 4 + 4]
- mov [array + edx * 4], ebx
- mov [array + edx * 4 + 4], eax
- not_swap:
- inc edx
- loop inner_loop
- loop outer_loop
- mov ecx, array_size
- mov edx, buffer
- call print_string
- print_loop:
- mov eax, [array + ecx * 4 - 4]
- call print_number
- dec ecx
- jnz print_loop
- call crlf
- call [ExitProcess]
- proc print_string
- push ecx
- push edx
- mov ecx, -1
- .repeat
- inc ecx
- mov al, [edx + ecx]
- cmp al, 0
- jz .done
- invoke StdOut, al
- jmp .repeat
- .done:
- pop edx
- pop ecx
- ret
- endp
- proc print_number
- push eax
- push ebx
- mov ebx, 10
- mov edx, 0
- div ebx
- cmp eax, 0
- jz .done
- push edx
- call print_number
- pop edx
- .done:
- add dl, '0'
- invoke StdOut, dl
- pop ebx
- pop eax
- ret
- endp
- proc crlf
- invoke StdOut, 13
- invoke StdOut, 10
- ret
- endp
- section '.idata' import data readable writeable
- library kernel32, 'kernel32.dll',\
- user32, 'user32.dll'
- import kernel32,\
- ExitProcess, 'ExitProcess'
- import user32,\
- wsprintf, 'wsprintfA'
- section '.text' code readable executable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement