-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtema1.asm
More file actions
198 lines (177 loc) · 4.03 KB
/
Copy pathtema1.asm
File metadata and controls
198 lines (177 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
%include "io.inc"
extern getAST
extern freeAST
struc myStruct
data: resd 1
leftChild: resd 1
rightChild: resd 1
endstruc
section .bss
; La aceasta adresa, scheletul stocheaza radacina arborelui
root: 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
push eax
call verifica_daca_e_semn
add esp, 4
PRINT_DEC 4, esi
; NU MODIFICATI
; Se elibereaza memoria alocata pentru arbore
push dword [root]
xor eax, eax
leave
ret
verifica_daca_e_semn:
push ebp
mov ebp, esp
push eax
push ebx
mov eax, [ebp + 8]
mov ebx, [eax]
mov ecx, [ebx]
adunare:
cmp ecx, "+"
jne scadere
;daca e adunare verificam pe stanga
push dword[eax +4]
call verifica_daca_e_semn
add esp, 4
push ecx
push esi
;si pe dreapta
push dword[eax + 8]
call verifica_daca_e_semn
add esp,4
;cand se ajunge la numere le intorc prin esi
;si le adun/scad/impart/inmultesc in functie de operatie
pop ecx
add esi, ecx
pop ecx
cmp ecx, 48
jg sari_peste
scadere:
cmp ecx, "-"
jne inmultire
push dword[eax +4]
call verifica_daca_e_semn
add esp, 4
push ecx
push esi
push dword[eax + 8]
call verifica_daca_e_semn
add esp,4
pop ecx
sub ecx, esi
mov esi, ecx
pop ecx
cmp ecx, 48
jg sari_peste
inmultire:
cmp ecx, "*"
jne impartire
push dword[eax +4]
call verifica_daca_e_semn
add esp, 4
push ecx
push esi
push dword[eax + 8]
call verifica_daca_e_semn
add esp,4
pop eax
imul esi
mov esi, eax
pop ecx
cmp ecx, 48
jg sari_peste
impartire:
cmp ecx, "/"
jne out_1
push dword[eax +4]
call verifica_daca_e_semn
add esp, 4
push ecx
push esi
push dword[eax + 8]
call verifica_daca_e_semn
add esp,4
pop eax
cdq
idiv esi
mov esi, eax
pop ecx
cmp ecx, 48
jg sari_peste
out_1:
push ebx
call convertCharToInt
add esp, 4
mov esi, edi
sari_peste:
pop ebx
pop eax
leave
ret
;Convert char to int
;verificam daca e negativ
negativ:
mov esi, 1
inc ebx
jmp aux
;in caz ca e negativ il negam
negativ_1:
neg edi
jmp out_convertCharToInt
;functia principala
convertCharToInt:
push ebp
mov ebp, esp
push ebx
push ecx
push esi
xor edi, edi
xor ebx, ebx
xor ecx, ecx
xor esi, esi
mov ebx, [ebp + 8]
mov cl, byte[ebx]
;PRINT_CHAR CL
;NEWLINE
cmp cl, '-'
je negativ
;verifica fiecare caracter de tip char si il transforma
aux:
mov cl, byte[ebx]
cmp cl, 0
je out
;PRINT_CHAR CL
;NEWLINE
inc ebx
cmp cl, '9'
ja out
cmp cl, '0'
jb out
sub ecx, '0'
imul edi, 10
add edi, ecx
jmp aux
;aici verifica daca a fost negativ
out:
cmp esi, 1
je negativ_1
out_convertCharToInt:
pop esi
pop ecx
pop ebx
leave
ret
;Adrian Argint
; 323CB