Guest User

Untitled

a guest
Nov 22nd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. %include "includes/io.inc"
  2.  
  3. extern getAST
  4. extern freeAST
  5.  
  6. section .bss
  7. ; La aceasta adresa, scheletul stocheaza radacina arborelui
  8. root: resd 1
  9. section .data
  10. fake_stack TIMES 100000000 dw 0
  11. section .text
  12. ;ascii:
  13. ; push ebp
  14. ; mov ebp, esp
  15. ; mov ebx, [ebp + 8]
  16. ; mov dl, byte[ebx]
  17. ; xor eax, eax
  18. ; test dl, dl
  19. ; je rip
  20. ; cmp dl, "-"
  21. ; je negative
  22.  
  23. ;poz:
  24. ; mov dl, byte[ebx]
  25. ;test dl, dl
  26. ; je rip
  27. ;sub edx, 48
  28. ; imul eax,10
  29. ; add eax, edx
  30. ; inc ebx
  31. ; jmp poz
  32. ;
  33. ;negative:
  34. ; inc ebx
  35. ;negative_loop:
  36. ; mov dl, byte[ebx]
  37. ; test dl, dl
  38. ; je rip_neg
  39. ; sub edx, 48
  40. ; imul eax, 10
  41. ; add eax, edx
  42. ; inc ebx
  43. ; jmp negative_loop
  44. ;rip_neg:
  45. ; neg eax
  46. ;
  47. ;rip:
  48. ; leave
  49. ; ret
  50.  
  51.  
  52. parcurgere_fake:
  53. check_empty:
  54. cmp esi, -1
  55. je empty
  56. mov ebx, [fake_stack + 4 * esi]
  57. mov ecx, [ebx]
  58. cmp ecx, "+"
  59. je adunare
  60. ;cmp ecx, "-"
  61. ;je scadere
  62. ;cmp
  63. dec esi
  64. ; PRINT_DEC 4, [EBX]
  65. NEWLINE
  66. xor edx, edx
  67. xor eax, eax
  68. mov dl, byte[ebx]
  69. xor eax, eax
  70. test dl, dl
  71. je here
  72. cmp dl, "-"
  73. je negative
  74. poz:
  75. mov dl, byte[ebx]
  76. test dl, dl
  77. je here
  78. sub edx, 48
  79. imul eax,10
  80. add eax, edx
  81. inc ebx
  82. jmp poz
  83. negative:
  84. inc ebx
  85. negative_loop:
  86. mov dl, byte[ebx]
  87. test dl, dl
  88. je rip_neg
  89. sub edx, 48
  90. imul eax, 10
  91. add eax, edx
  92. inc ebx
  93. jmp negative_loop
  94. rip_neg:
  95. neg eax
  96. here:
  97. push eax
  98. jmp check_empty
  99.  
  100. adunare:
  101. pop eax
  102. ;mov eax, [eax]
  103. pop ebx
  104. ;mov ebx, [ebx]
  105. add eax, ebx
  106. push eax
  107. dec esi
  108. jmp check_empty
  109.  
  110.  
  111.  
  112.  
  113. empty:
  114. ;PRINT_DEC 4, [EAX]
  115. pop eax
  116. PRINT_DEC 4, EAX
  117. leave
  118. ret
  119. parcurgere_arbore:
  120. push ebp
  121. mov ebp, esp
  122. mov eax, [ebp + 8]
  123. ;mov eax, [eax]
  124. verify:
  125. test eax, eax
  126. je return
  127. ; mov edx, [eax]
  128. ; PRINT_STRING [EDX]
  129. add_in_fake:
  130. mov eax, [eax]
  131. mov [fake_stack + 4 * esi], eax
  132.  
  133. inc esi
  134.  
  135. left:
  136. mov eax, [ebp + 8]
  137. mov eax, [eax + 4]
  138. push eax
  139. call parcurgere_arbore
  140. add esp,4
  141. right:
  142. mov eax, [ebp + 8]
  143. mov eax, [eax + 8]
  144. push eax
  145. call parcurgere_arbore
  146. add esp,4
  147.  
  148. return:
  149. leave
  150. ret
  151. global main
  152. main:
  153. mov ebp, esp; for correct debugging
  154. ; NU MODIFICATI
  155. push ebp
  156. mov ebp, esp
  157.  
  158. ; Se citeste arborele si se scrie la adresa indicata mai sus
  159. call getAST
  160. mov [root], eax
  161.  
  162. ; Implementati rezolvarea aici:
  163. xor esi, esi
  164. sub esp, 4
  165. push eax
  166. call parcurgere_arbore
  167. add esp,4
  168. dec esi
  169. call parcurgere_fake
  170.  
  171. ; NU MODIFICATI
  172. ; Se elibereaza memoria alocata pentru arbore
  173. push dword [root]
  174. call freeAST
  175.  
  176. xor eax, eax
  177. leave
  178. ret
Advertisement
Add Comment
Please, Sign In to add comment