Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. %include "includes/io.inc"
  2.  
  3. struc Struc
  4. info: resd 1
  5. left: resd 1
  6. right: resd 1
  7. endstruc
  8.  
  9. extern getAST
  10. extern freeAST
  11.  
  12. section .bss
  13. ; La aceasta adresa, scheletul stocheaza radacina arborelui
  14. root: resd 1
  15. op_left: resd 1
  16. op_right: resd 1
  17. negative: resb 1
  18.  
  19. section .text
  20. global main
  21. main:
  22. mov ebp, esp; for correct debugging
  23. ; NU MODIFICATI
  24. push ebp
  25. mov ebp, esp
  26.  
  27. ; Se citeste arborele si se scrie la adresa indicata mai sus
  28. call getAST
  29. mov [root], eax
  30.  
  31. ; Implementati rezolvarea aici:
  32. call print
  33. mov eax, [root + info]
  34. mov eax, [eax]
  35. PRINT_DEC 4, [eax]
  36.  
  37. ; NU MODIFICATI
  38. ; Se elibereaza memoria alocata pentru arbore
  39. push dword [root]
  40. call freeAST
  41.  
  42. xor eax, eax
  43. leave
  44. ret
  45.  
  46. print:
  47. push eax
  48. mov eax, [eax + info]
  49. mov ebx, eax
  50. mov eax, [eax]
  51.  
  52. cmp al, '/'
  53. jg str_to_int
  54.  
  55. cmp ah, 0
  56. jne set_neg
  57.  
  58. pop eax
  59. push eax
  60. mov eax, [eax + left]
  61. call print
  62.  
  63. pop eax
  64. push eax
  65. mov eax, [eax + right]
  66. call print
  67.  
  68. pop eax
  69. push eax
  70. mov eax, [eax + left]
  71. mov eax, [eax + info]
  72. mov eax, [eax]
  73. cdq
  74.  
  75. pop ebx
  76. push ebx
  77. mov ebx, [ebx + right]
  78. mov ebx, [ebx + info]
  79. mov ebx, [ebx]
  80.  
  81. pop ecx
  82. push ecx
  83. mov ecx, [ecx + info]
  84. mov ecx, [ecx]
  85.  
  86. cmp ecx, '+'
  87. je suma
  88.  
  89. cmp ecx, '-'
  90. je diferenta
  91.  
  92. cmp ecx, '*'
  93. je produs
  94.  
  95. idiv ebx
  96. jmp set_and_leave
  97.  
  98. suma:
  99. add eax, ebx
  100. jmp set_and_leave
  101.  
  102. diferenta:
  103. sub eax, ebx
  104. jmp set_and_leave
  105.  
  106. produs:
  107. imul ebx
  108. jmp set_and_leave
  109.  
  110. set_and_leave:
  111. pop ecx
  112. push ecx
  113. mov ecx, [ecx + info]
  114. mov [ecx], eax
  115.  
  116. jmp end
  117.  
  118. set_neg:
  119. inc byte [negative]
  120.  
  121. str_to_int:
  122. xor eax, eax
  123.  
  124. cmp byte [negative], 0
  125. je positive
  126. inc ebx
  127.  
  128. positive:
  129. mov ecx, 10
  130.  
  131. cmp dword [ebx], 0
  132. je set
  133. imul ecx
  134.  
  135. mov ecx, [ebx]
  136. sub cl, '0'
  137. push edx
  138. xor edx, edx
  139. movzx edx, cl
  140. add eax, edx
  141. pop edx
  142. inc ebx
  143. jmp positive
  144.  
  145. set:
  146. cmp byte [negative], 0
  147. je save
  148.  
  149. not eax
  150. inc eax
  151.  
  152. dec byte [negative]
  153.  
  154. save:
  155. mov ebx, eax
  156. pop eax
  157. push eax
  158. mov eax, [eax + info]
  159. mov [eax], ebx
  160.  
  161. end:
  162. pop eax
  163. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement