Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %include "includes/io.inc"
- struc Node
- data: 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
- isNeg: resd 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 + data]
- 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:
- mov ebx, [eax + data]
- mov ebx, [ebx]
- mov dl, '-'
- mov cl, bl
- cmp cl, dl
- mov edx, '0'
- mov ecx, 10
- jne check_if_number
- cmp ebx, '-'
- ;mov ebx, [eax + data]
- ;inc ebx
- ;mov ebx, [ebx]
- jne convert
- check_if_number:
- cmp bl, dl
- je convert
- inc edx
- loop check_if_number
- label1:
- push eax
- mov eax, [eax + left]
- call print
- pop eax
- push eax
- mov eax, [eax + right]
- call print
- pop eax
- mov ebx, [eax + data]
- cmp dword [ebx], '+'
- je sum
- cmp dword [ebx], '-'
- je difference
- cmp dword [ebx], '*'
- je multiply
- cmp dword [ebx], '/'
- je divide
- convert:
- mov cl, bl
- mov dl, '-'
- cmp cl, dl
- mov ebx, [eax + data]
- jne pozi
- inc ebx
- mov dword [isNeg], "yes"
- pozi:
- xor edx, edx
- call atoi
- mov ecx, [eax + data]
- mov [ecx], ebx
- end:
- ret
- difference:
- mov ecx, [eax + left]
- mov ecx, [ecx + data]
- mov ecx, [ecx]
- mov edx, [eax + right]
- mov edx, [edx + data]
- mov edx, [edx]
- sub ecx, edx
- mov [ebx], ecx
- jmp end
- divide:
- push eax
- mov ecx, [eax + right]
- mov ecx, [ecx + data]
- mov ecx, [ecx]
- mov eax, [eax + left]
- mov eax, [eax + data]
- mov eax, [eax]
- cdq
- idiv ecx
- mov [ebx], eax
- pop eax
- jmp end
- sum:
- mov ecx, [eax + left]
- mov ecx, [ecx + data]
- mov ecx, [ecx]
- push eax
- mov eax, [eax + right]
- mov eax, [eax + data]
- mov eax, [eax]
- add ecx, eax
- pop eax
- mov ebx, [eax + data]
- mov [ebx], ecx
- jmp end
- multiply:
- push eax
- mov ecx, [eax + right]
- mov ecx, [ecx + data]
- mov ecx, [ecx]
- mov eax, [eax + left]
- mov eax, [eax + data]
- mov eax, [eax]
- imul ecx
- mov [ebx], eax
- pop eax
- jmp end
- atoi:
- push ebx
- mov ebx, [ebx]
- test ebx, ebx
- je stop
- sub ebx, '0'
- push eax
- mov eax, edx
- shl edx, 3
- add edx, eax
- add edx, eax
- xor eax, eax
- mov al, bl
- add edx, eax
- pop eax
- pop ebx
- inc ebx
- jmp atoi
- stop:
- cmp dword [isNeg], "yes"
- jne positive
- mov dword [isNeg], "no"
- not edx
- inc edx
- positive:
- mov ebx, edx
- add esp, 4
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement