Advertisement
beautifulnofer

Untitled

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