Advertisement
filashkov

Untitled

May 12th, 2020
459
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extern fprintf
  2. extern fscanf
  3. extern fopen
  4. extern qsort
  5. extern scanf
  6. extern fclose
  7.  
  8. section .bss
  9.     a resd 0xACE
  10.  
  11. section .data
  12.     num dd 0
  13.     scanner db `%d`, 0
  14.  
  15. section .rodata
  16.     iomode db `%d`, 0
  17.     output_mode db `%d `, 0
  18.     input_name db "input.txt", 0
  19.     output_name db `output.txt`, 0
  20.     fileInputMode db `r`, 0
  21.     fileOutputMode db `w+`, 0
  22.  
  23. section .text
  24. global main
  25. main:
  26.     mov ebp, esp
  27.     and esp, 0xfffffff0
  28.    
  29.     sub esp, 8
  30.     push fileInputMode
  31.     push input_name
  32.     call fopen
  33.    
  34.     add esp, 12
  35.     push num
  36.     push iomode
  37.     push eax
  38.     mov edi, 0
  39.    
  40. .input_while:  
  41.     call fscanf
  42.     cmp eax, 0
  43.         jle .stop_input_while  
  44.        
  45.             mov esi, [num]
  46.             mov [a + 4 * edi], esi
  47.                    
  48.         inc edi
  49.     jmp .input_while
  50. .stop_input_while:
  51.  
  52.     call fclose
  53.     add esp, 16
  54.      
  55.     push comporator  ; �������� �������� - ����������
  56.     push 4           ; ������ �������� - ������ �������� �������
  57.     push edi         ; ������ �������� - ������ �������
  58.     push a           ; ������ �������� - ��������� �� ������ �������
  59.     call qsort
  60.     add esp, 8
  61.    
  62.     push fileOutputMode
  63.     push output_name
  64.     call fopen
  65.     add esp, 12
  66.    
  67.     push 123         ; ������ �������� - ��� �������
  68.     push output_mode ; ������ �������� - ����� �����
  69.     push eax         ; ������ �������� - ��������� �� ����
  70.    
  71.     mov esi, 0
  72. .print_for:
  73.     cmp esi, edi
  74.         jz .stop_print_for
  75.            
  76.             mov ebx, [a + 4 * esi]
  77.             mov dword [esp + 8], ebx
  78.             call fprintf
  79.        
  80.         inc esi
  81.     jmp .print_for
  82. .stop_print_for:    
  83.    
  84.     mov esp, ebp
  85.     xor eax, eax
  86.     ret
  87.    
  88.    
  89. global comporator
  90. comporator:
  91. .prolog:
  92.     push ebp
  93.     mov ebp, esp
  94.     push ebx    
  95.     ;push edi
  96.     ;push esi
  97.     mov eax, dword [ebp + 8]  ; ���������� ������� ���������
  98.     mov ebx, dword [ebp + 12] ; ���������� ������� ���������
  99.     mov eax, [eax]            ; omg
  100.     mov ebx, [ebx]
  101. .end_of_prolog:
  102.     cmp eax, ebx
  103.         jz .equal
  104.    
  105.     cmp eax, ebx
  106.         jl .minus
  107.      
  108.     mov eax, 1
  109.     jmp .epilog
  110.    
  111. .minus:
  112.     mov eax, -1
  113.     jmp .epilog
  114.    
  115. .equal:
  116.     mov eax, 0
  117.     jmp .epilog
  118.    
  119. .epilog:
  120.     ;pop esi
  121.     ;pop edi
  122.     pop ebx
  123.     mov esp, ebp
  124.     pop ebp
  125.     ret
  126. .end_of_epilog:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement