Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %include "includes/io.inc"
- struc Struc
- info: resd 1
- left: resd 1
- right: resd 1
- endstruc
- extern getAST
- extern freeAST
- section .bss
- ; La aceasta adresa, scheletul stocheaza radacina arborelui
- root: resd 1
- op_left: resd 1
- op_right: resd 1
- negative: resb 1
- section .text
- 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:
- call print
- mov eax, [root + info]
- mov eax, [eax]
- PRINT_DEC 4, [eax]
- ; NU MODIFICATI
- ; Se elibereaza memoria alocata pentru arbore
- push dword [root]
- call freeAST
- xor eax, eax
- leave
- ret
- print:
- push eax
- mov eax, [eax + info]
- mov ebx, eax
- mov eax, [eax]
- cmp al, '/'
- jg str_to_int
- cmp ah, 0
- jne set_neg
- pop eax
- push eax
- mov eax, [eax + left]
- call print
- pop eax
- push eax
- mov eax, [eax + right]
- call print
- pop eax
- push eax
- mov eax, [eax + left]
- mov eax, [eax + info]
- mov eax, [eax]
- cdq
- pop ebx
- push ebx
- mov ebx, [ebx + right]
- mov ebx, [ebx + info]
- mov ebx, [ebx]
- pop ecx
- push ecx
- mov ecx, [ecx + info]
- mov ecx, [ecx]
- cmp ecx, '+'
- je suma
- cmp ecx, '-'
- je diferenta
- cmp ecx, '*'
- je produs
- idiv ebx
- jmp set_and_leave
- suma:
- add eax, ebx
- jmp set_and_leave
- diferenta:
- sub eax, ebx
- jmp set_and_leave
- produs:
- imul ebx
- jmp set_and_leave
- set_and_leave:
- pop ecx
- push ecx
- mov ecx, [ecx + info]
- mov [ecx], eax
- jmp end
- set_neg:
- inc byte [negative]
- str_to_int:
- xor eax, eax
- cmp byte [negative], 0
- je positive
- inc ebx
- positive:
- mov ecx, 10
- cmp dword [ebx], 0
- je set
- imul ecx
- mov ecx, [ebx]
- sub cl, '0'
- push edx
- xor edx, edx
- movzx edx, cl
- add eax, edx
- pop edx
- inc ebx
- jmp positive
- set:
- cmp byte [negative], 0
- je save
- not eax
- inc eax
- dec byte [negative]
- save:
- mov ebx, eax
- pop eax
- push eax
- mov eax, [eax + info]
- mov [eax], ebx
- end:
- pop eax
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement