Advertisement
beautifulnofer

Untitled

Apr 27th, 2021
977
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %include "io.inc"
  2.  
  3. section .bss
  4.     esp_saved resd 1
  5.     command resb 1
  6.     num1 resd 1
  7.     num2 resd 1
  8.  
  9. section .data
  10.     forms db '%s', 0
  11.     formc db '%c', 0
  12.     formd db '%d', 0
  13.     formdd db '%d %d', 10, 0
  14.  
  15. section .text
  16. global CMAIN
  17. CEXTERN scanf
  18. CEXTERN printf
  19. CEXTERN malloc
  20. CEXTERN free
  21. CEXTERN strcmp
  22. CMAIN:
  23.     mov dword[esp_saved], esp
  24.     and esp, -16
  25.     sub esp, 16
  26.    
  27.     mov esi, 0
  28.    
  29. .L:
  30.     mov dword[esp], formc
  31.     mov dword[esp + 4], command
  32.     call scanf
  33.     cmp byte[command], 'F'
  34.     jz .IF
  35.     cmp byte[command], 'A'
  36.     jz .ELSEIF1
  37.     cmp byte[command], 'S'
  38.     jz .ELSEIF2
  39.     cmp byte[command], 'D'
  40.     jz .ELSEIF3
  41.     jmp .L
  42. .IF: ;F
  43.     jmp .E
  44. .ELSEIF1: ;A
  45.     mov dword[esp], formdd
  46.     mov dword[esp + 4], num1
  47.     mov dword[esp + 8], num2
  48.     call scanf
  49.     mov dword[esp], esi
  50.     mov ebx, dword[num1]
  51.     mov dword[esp + 4], ebx
  52.     mov ebx, dword[num2]
  53.     mov dword[esp + 8], ebx
  54.     call insert
  55.     cmp esi, 0
  56.     cmovz esi, eax
  57.     jmp .L
  58. .ELSEIF2: ;S
  59.     mov dword[esp], formd
  60.     mov dword[esp + 4], num1
  61.     call scanf
  62.     mov dword[esp], esi
  63.     mov ebx, dword[num1]
  64.     mov dword[esp + 4], ebx
  65.     call find
  66.     cmp eax, 0
  67.     jz .L
  68.     mov dword[esp], formdd
  69.     mov ebx, dword[eax]
  70.     mov dword[esp + 4], ebx
  71.     mov ebx, dword[eax + 4]
  72.     mov dword[esp + 8], ebx
  73.     call printf
  74.     jmp .L
  75. .ELSEIF3: ;D
  76.     mov dword[esp], formd
  77.     mov dword[esp + 4], num1
  78.     call scanf
  79.     mov dword[esp], esi
  80.     mov ebx, dword[num1]
  81.     mov dword[esp + 4], ebx
  82.     call delete
  83.     mov esi, edx
  84.     jmp .L
  85. .E:
  86.  
  87.     sub esp, 12
  88.     push esi
  89.     call erase
  90.     add esp, 4
  91.    
  92. .END:
  93.     mov esp, dword[esp_saved]
  94.     xor eax, eax
  95.     ret
  96.  
  97.  
  98.  
  99. global tree
  100. tree:
  101.     push ebp
  102.     mov ebp, esp
  103.    
  104.     sub esp, 12
  105.     push ecx
  106.     push edx
  107.     push 16
  108.     call malloc
  109.     add esp, 4
  110.     pop edx
  111.     pop ecx
  112.     add esp, 12
  113.    
  114.     mov edx, dword[ebp + 8]
  115.     mov dword[eax], edx
  116.     mov edx, dword[ebp + 12]
  117.     mov dword[eax + 4], edx
  118.     mov dword[eax + 8], 0
  119.     mov dword[eax + 12], 0
  120.    
  121.     leave
  122.     ret
  123.  
  124. global insert
  125. insert:
  126.     push ebp
  127.     mov ebp, esp
  128.     push ebx
  129.    
  130.     mov ebx, dword[ebp + 8]
  131.     mov ecx, dword[ebp + 12]
  132.     sub esp, 12
  133.     push dword[ebp + 16]
  134.     push dword[ebp + 12]
  135.     call tree
  136.     add esp, 20
  137. .L1:
  138.     cmp ebx, 0
  139.     jz .E1
  140.     cmp ecx, dword[ebx]
  141.     jz .IF1
  142.     jg .ELSEIF11
  143.     jl .ELSEIF12
  144. .IF1:
  145.     mov ecx, dword[ebp + 16]
  146.     mov dword[ebx + 4], ecx
  147.     jmp .E1
  148. .ELSEIF11:
  149.     cmp dword[ebx + 12], 0
  150.     cmovnz ebx, dword[ebx + 12]
  151.     jnz .L1
  152.     cmovz edx, eax
  153.     mov dword[ebx + 12], edx
  154.     jz .E1
  155. .ELSEIF12:
  156.     cmp dword[ebx + 8], 0
  157.     cmovnz ebx, dword[ebx + 8]
  158.     jnz .L1
  159.     cmovz edx, eax
  160.     mov dword[ebx + 8], edx
  161.     jz .E1
  162. .ENDIF1:
  163.     jmp .L1
  164. .E1:
  165.  
  166.     pop ebx
  167.     leave
  168.     ret
  169.  
  170. global find
  171. find:
  172.     push ebp
  173.     mov ebp, esp
  174.    
  175.     cmp dword[ebp + 8], 0
  176.     jz .IF2
  177.     mov edx, dword[ebp + 8]
  178.     mov edx, dword[edx]
  179.     cmp edx, dword[ebp + 12]
  180.     jz .IF2
  181.     cmp dword[ebp + 12], edx
  182.     jl .ELSEIF21
  183.     jmp .ELSEIF22
  184. .IF2: ;ebp+8 == null || ebp+12 == [ebp+8]+0
  185.     mov eax, dword[ebp + 8]
  186.     jmp .ENDIF2
  187. .ELSEIF21: ;ebp+12 < [ebp+8]+0
  188.     mov edx, dword[ebp + 8]
  189.     mov edx, dword[edx + 8]
  190.     push edx
  191.     push dword[ebp + 16]
  192.     push dword[ebp + 12]
  193.     push edx
  194.     call find
  195.     add esp, 12
  196.     pop edx
  197.     jmp .ENDIF2
  198. .ELSEIF22: ;ebp+12 > [ebp+8]+0
  199.     mov edx, dword[ebp + 8]
  200.     mov edx, dword[edx + 12]
  201.     push edx
  202.     push dword[ebp + 16]
  203.     push dword[ebp + 12]
  204.     push edx
  205.     call find
  206.     add esp, 12
  207.     pop edx
  208.     jmp .ENDIF2
  209. .ENDIF2:
  210.    
  211.     leave
  212.     ret
  213.  
  214. global min
  215. min:
  216.     push ebp
  217.     mov ebp, esp
  218.    
  219.     mov eax, dword[ebp + 8]
  220.     mov eax, dword[eax + 8]
  221.     cmp eax, 0
  222.     jz .IF3
  223.     jmp .ELSEIF3
  224. .IF3: ;[ebp+8]+8 == null
  225.     mov eax, dword[ebp + 8]
  226.     jmp .ENDIF3
  227. .ELSEIF3:
  228.     push eax
  229.     call min
  230.     add esp, 4
  231.     jmp .ENDIF3
  232. .ENDIF3:
  233.    
  234.     leave
  235.     ret
  236.  
  237. global delete
  238. delete:
  239.     push ebp
  240.     mov ebp, esp
  241.     push ebx
  242.    
  243.     mov ebx, dword[ebp + 8]
  244.     cmp ebx, 0
  245.     jz .IF4
  246.     jmp .ENDIF4
  247. .IF4:
  248.     mov edx, 0
  249.     jmp .ENDdelete
  250. .ENDIF4:
  251.    
  252.     mov ebx, dword[ebx]
  253.     cmp dword[ebp + 12], ebx
  254.     mov ebx, dword[ebp + 8]
  255.     jl .IF5
  256.     jg .ELSEIF51
  257.     mov ebx, dword[ebp + 8]
  258.     cmp dword[ebx + 8], 0
  259.     jz .ELSEIF53
  260.     cmp dword[ebx + 12], 0
  261.     jz .ELSEIF53
  262.     jmp .ELSEIF52
  263. .IF5: ;ebp+12 < [ebp+8]+0
  264.     push ebx
  265.     sub esp, 8
  266.     push dword[ebp + 12]
  267.     push dword[ebx + 8]
  268.     call delete
  269.     add esp, 16
  270.     pop ebx
  271.     mov dword[ebx + 8], edx
  272.     jmp .ENDIF5
  273. .ELSEIF51: ;ebp+12 > [ebp+8]+0
  274.     push ebx
  275.     sub esp, 8
  276.     push dword[ebp + 12]
  277.     push dword[ebx + 12]
  278.     call delete
  279.     add esp, 16
  280.     pop ebx
  281.     mov dword[ebx + 12], edx
  282.     jmp .ENDIF5
  283. .ELSEIF52: ;[ebp+8]+8 != null && [ebp+8]+12 != null
  284.     push dword[ebx + 12]
  285.     call min
  286.     add esp, 4
  287.     mov edx, dword[eax]
  288.     mov dword[ebx], edx
  289.     mov edx, dword[eax + 4]
  290.     mov dword[ebx + 4], edx
  291.     push ebx
  292.     sub esp, 8
  293.     push dword[ebx]
  294.     push dword[ebx + 12]
  295.     call delete
  296.     add esp, 16
  297.     pop ebx
  298.     mov dword[ebx + 12], edx
  299.     jmp .ENDIF5
  300. .ELSEIF53:
  301.     mov eax, ebx
  302.     cmp dword[ebx + 8], 0
  303.     jnz .IF6
  304.     cmp dword[ebx + 12], 0
  305.     jnz .ELSEIF61
  306.     jmp .ELSEIF62
  307. .IF6:
  308.     mov ebx, dword[ebx + 8]
  309.     mov dword[ebp + 8], ebx
  310.     jmp .ENDIF6
  311. .ELSEIF61:
  312.     mov ebx, dword[ebx + 12]
  313.     mov dword[ebp + 8], ebx
  314.     jmp .ENDIF6
  315. .ELSEIF62:
  316.     mov dword[ebp + 8], 0
  317.     jmp .ENDIF6
  318. .ENDIF6:
  319.     push eax
  320.     call free
  321.     add esp, 4
  322.     jmp .ENDIF5
  323. .ENDIF5:
  324.     mov edx, dword[ebp + 8]
  325.    
  326. .ENDdelete:
  327.     pop ebx
  328.     leave
  329.     ret
  330.  
  331. global erase
  332. erase:
  333.     push ebp
  334.     mov ebp, esp
  335.    
  336.     cmp dword[ebp + 8], 0
  337.     jz .ENDerase
  338.     mov eax, dword[ebp + 8]
  339.     push eax
  340.     push dword[eax + 8]
  341.     call erase
  342.     add esp, 4
  343.     pop eax
  344.     push eax
  345.     push dword[eax + 12]
  346.     call erase
  347.     add esp, 4
  348.     pop eax
  349.     push eax
  350.     push dword[ebp + 8]
  351.     call free
  352.     add esp, 8
  353.    
  354. .ENDerase:
  355.     leave
  356.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement