_takumi

hw3n7.asm

Feb 21st, 2022 (edited)
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %include "io.inc"
  2.  
  3. section .bss
  4.     arr resd 10000
  5.    
  6. section .data
  7.     index dd 0
  8.  
  9. section .text
  10. global CMAIN
  11. CMAIN:
  12.     mov ebp, esp; for correct debugging
  13.     GET_DEC 4, eax
  14.     mov ecx, 0
  15. .readarr:
  16.     cmp ecx, eax
  17.     jge .readarr_end
  18.     GET_DEC 4, edx
  19.     mov dword [arr + ecx * 4], edx
  20.     inc ecx
  21.     jmp .readarr
  22. .readarr_end:
  23.     mov ebx, 1
  24. .loop1:
  25.     cmp ebx, eax
  26.     jge .loop1_end
  27.     mov ecx, ebx
  28.     dec ecx
  29.     mov edx, dword [arr + ebx * 4]
  30. .loop2:
  31.     cmp ecx, 0
  32.     jl .loop2_end
  33.     cmp edx, dword [arr + ecx * 4]
  34.     jge .loop2_end
  35.     mov edi, dword [arr + ecx * 4 + 4]
  36.     mov esi, dword [arr + ecx * 4]
  37.     mov dword [arr + ecx * 4 + 4], esi
  38.     mov dword [arr + ecx * 4], edi
  39. .endif:
  40.     dec ecx
  41.     jmp .loop2
  42. .loop2_end:
  43.     inc ebx
  44.     jmp .loop1
  45. .loop1_end:
  46.     xor ecx, ecx
  47. .print:
  48.     cmp ecx, eax
  49.     jge .print_end
  50.     mov edx, dword [arr + ecx * 4]
  51.     PRINT_DEC 4, edx
  52.     PRINT_CHAR 32
  53.     inc ecx
  54.     jmp .print
  55. .print_end:
  56.     xor eax, eax
  57.     ret
Add Comment
Please, Sign In to add comment