Advertisement
dllbridge

BubleSorting FASM

May 8th, 2024
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. format PE console
  2. entry start
  3.  
  4. include 'win32a.inc'
  5.  
  6. section '.data' data readable writeable
  7.     array dd 5, 2, 9, 3, 1  ; пример массива для сортировки
  8.     array_size equ ($ - array) / 4
  9.  
  10. section '.code' code readable executable
  11.   start:
  12.     mov ecx, array_size
  13.  
  14.     outer_loop:
  15.       mov edx, 0
  16.       mov ebx, ecx
  17.       dec ebx
  18.  
  19.       inner_loop:
  20.         mov eax, [array + edx * 4]
  21.         cmp eax, [array + edx * 4 + 4]
  22.         jbe not_swap
  23.  
  24.         mov eax, [array + edx * 4]
  25.         mov ebx, [array + edx * 4 + 4]
  26.         mov [array + edx * 4], ebx
  27.         mov [array + edx * 4 + 4], eax
  28.  
  29.         not_swap:
  30.           inc edx
  31.           loop inner_loop
  32.  
  33.       loop outer_loop
  34.  
  35.     mov ecx, array_size
  36.  
  37.     print_loop:
  38.       mov eax, [array + ecx * 4 - 4]
  39.       print eax
  40.       dec ecx
  41.       jnz print_loop
  42.  
  43.     call [ExitProcess]
  44.  
  45. section '.idata' import data readable writeable
  46.   library kernel32, 'kernel32.dll',\
  47.           user32, 'user32.dll'
  48.  
  49.   import kernel32,\
  50.          ExitProcess, 'ExitProcess'
  51.  
  52.   import user32,\
  53.          wsprintf, 'wsprintfA'
  54.  
  55. section '.text' code readable executable
  56.   proc print
  57.     enter
  58.       invoke wsprintf, buffer, '%d', [ebp + 8]
  59.       invoke StdOut, buffer
  60.     return
  61.   endp
  62.  
  63. section '.bss' data readable writeable
  64.   buffer rb 16
  65.  
  66. section '.reloc' fixups data discardable
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement