Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %include "io.inc"
  2.  
  3.  
  4. section .bss
  5. n resd 1
  6. a resd 10000
  7.  
  8. section .text
  9. swap:
  10.     push ebp
  11.     mov ebp, esp
  12.     push ebx  
  13.    
  14.     mov eax, dword[ebp + 8]; p1
  15.     mov ebx, dword[ebp + 12]; p2
  16.    
  17.     mov eax, dword[eax]
  18.     PRINT_DEC 4, eax
  19.     NEWLINE
  20.     mov ebx, dword[ebx]
  21.     PRINT_DEC 4, ebx
  22.     NEWLINE
  23.    
  24.     mov eax, dword[ebp + 8]; p1
  25.     mov ebx, dword[ebp + 12]; p2
  26.    
  27.     mov edx, dword[eax]
  28.    
  29.    
  30.     mov dword[eax], ebx
  31.     mov dword[ebx], eax
  32.    
  33.     pop ebx
  34.     mov esp, ebp
  35.     pop ebp
  36.     ret
  37.  
  38. sort:
  39.     push ebp
  40.     mov ebp, esp
  41.     push ebx  
  42.    
  43.     ;dword[ebp + 8] pointer to a
  44.     ;dword[ebp + 12] n
  45.    
  46.     .loop1:
  47.         mov ebx, 1
  48.         .loop2:
  49.             mov ecx, dword[ebp + 8]; a
  50.             mov ecx, dword[ecx + 4 * ebx - 4]; a[i - 1]
  51.            
  52.             mov edx, dword[ebp + 8]; a
  53.             mov edx, dword[edx + 4 * ebx]; a[i]
  54.            
  55.             cmp ecx, edx
  56.             jng .skip
  57.                 ;swap a[i - 1], a[i]
  58.                 mov ecx, dword[ebp + 8]
  59.                 lea ecx, [ecx + 4 * ebx - 4]
  60.                
  61.                 mov edx, dword[ebp + 8]
  62.                 lea edx, [edx + 4 * ebx]
  63.                
  64.                 push ecx
  65.                 push edx
  66.                 call swap
  67.                 pop edx
  68.                 pop edx
  69.             .skip:
  70.            
  71.             inc ebx
  72.             cmp ebx, dword[ebp + 12]
  73.             jl .loop2
  74.            
  75.         dec dword[ebp + 12]      
  76.         cmp dword[ebp + 12], 0
  77.         jg .loop1
  78.        
  79.    
  80.     pop ebx
  81.     mov esp, ebp
  82.     pop ebp
  83.     ret
  84.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
  85.                                                                                                                                                                                                                                                                                                                    
  86. global CMAIN
  87. CMAIN:
  88.     GET_DEC 4, n
  89.     xor eax, eax
  90.     .input_loop:
  91.         GET_DEC 4, [a + 4 * eax]
  92.         inc eax
  93.         cmp eax, dword[n]
  94.         jl .input_loop
  95.    
  96.     push dword[n]
  97.     push a
  98.     call sort
  99.     pop edx
  100.     pop edx  
  101.    
  102.      xor eax, eax
  103.     .output_loop:
  104.         PRINT_DEC 4, [a + 4 * eax]
  105.         PRINT_CHAR " "
  106.         inc eax
  107.         cmp eax, dword[n]
  108.         jl .output_loop
  109.    
  110.     .break:
  111.     xor eax, eax
  112.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement