Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %include "includes/io.inc"
- extern getAST
- extern freeAST
- section .bss
- ; La aceasta adresa, scheletul stocheaza radacina arborelui
- root: resd 1
- section .data
- fake_stack TIMES 100000000 dw 0
- section .text
- ;ascii:
- ; push ebp
- ; mov ebp, esp
- ; mov ebx, [ebp + 8]
- ; mov dl, byte[ebx]
- ; xor eax, eax
- ; test dl, dl
- ; je rip
- ; cmp dl, "-"
- ; je negative
- ;poz:
- ; mov dl, byte[ebx]
- ;test dl, dl
- ; je rip
- ;sub edx, 48
- ; imul eax,10
- ; add eax, edx
- ; inc ebx
- ; jmp poz
- ;
- ;negative:
- ; inc ebx
- ;negative_loop:
- ; mov dl, byte[ebx]
- ; test dl, dl
- ; je rip_neg
- ; sub edx, 48
- ; imul eax, 10
- ; add eax, edx
- ; inc ebx
- ; jmp negative_loop
- ;rip_neg:
- ; neg eax
- ;
- ;rip:
- ; leave
- ; ret
- parcurgere_fake:
- check_empty:
- cmp esi, -1
- je empty
- mov ebx, [fake_stack + 4 * esi]
- mov ecx, [ebx]
- cmp ecx, "+"
- je adunare
- ;cmp ecx, "-"
- ;je scadere
- ;cmp
- dec esi
- ; PRINT_DEC 4, [EBX]
- NEWLINE
- xor edx, edx
- xor eax, eax
- mov dl, byte[ebx]
- xor eax, eax
- test dl, dl
- je here
- cmp dl, "-"
- je negative
- poz:
- mov dl, byte[ebx]
- test dl, dl
- je here
- sub edx, 48
- imul eax,10
- add eax, edx
- inc ebx
- jmp poz
- negative:
- inc ebx
- negative_loop:
- mov dl, byte[ebx]
- test dl, dl
- je rip_neg
- sub edx, 48
- imul eax, 10
- add eax, edx
- inc ebx
- jmp negative_loop
- rip_neg:
- neg eax
- here:
- push eax
- jmp check_empty
- adunare:
- pop eax
- ;mov eax, [eax]
- pop ebx
- ;mov ebx, [ebx]
- add eax, ebx
- push eax
- dec esi
- jmp check_empty
- empty:
- ;PRINT_DEC 4, [EAX]
- pop eax
- PRINT_DEC 4, EAX
- leave
- ret
- parcurgere_arbore:
- push ebp
- mov ebp, esp
- mov eax, [ebp + 8]
- ;mov eax, [eax]
- verify:
- test eax, eax
- je return
- ; mov edx, [eax]
- ; PRINT_STRING [EDX]
- add_in_fake:
- mov eax, [eax]
- mov [fake_stack + 4 * esi], eax
- inc esi
- left:
- mov eax, [ebp + 8]
- mov eax, [eax + 4]
- push eax
- call parcurgere_arbore
- add esp,4
- right:
- mov eax, [ebp + 8]
- mov eax, [eax + 8]
- push eax
- call parcurgere_arbore
- add esp,4
- return:
- leave
- ret
- global main
- main:
- mov ebp, esp; for correct debugging
- ; NU MODIFICATI
- push ebp
- mov ebp, esp
- ; Se citeste arborele si se scrie la adresa indicata mai sus
- call getAST
- mov [root], eax
- ; Implementati rezolvarea aici:
- xor esi, esi
- sub esp, 4
- push eax
- call parcurgere_arbore
- add esp,4
- dec esi
- call parcurgere_fake
- ; NU MODIFICATI
- ; Se elibereaza memoria alocata pentru arbore
- push dword [root]
- call freeAST
- xor eax, eax
- leave
- ret
Advertisement
Add Comment
Please, Sign In to add comment