@@ -6,6 +6,7 @@ section .bss
6
6
root resd 1
7
7
currentNode resd 1
8
8
isOperator resd 1
9
+ isNegativeAtoi resd 1
9
10
10
11
section .text
11
12
@@ -26,6 +27,15 @@ iocla_atoi: ;change string to number
26
27
xor ecx , ecx ;stores the result
27
28
xor ebx , ebx ;stores character
28
29
30
+ mov edx , 0
31
+ mov [ isNegativeAtoi ], edx ;the default way is that the number is positive
32
+ ;we check to see if the number is negative or not
33
+ mov bl , [ eax ]
34
+ cmp bl , '-' ;compare to minus character
35
+ jnz atoi_loop ;if it is not a minus sign just do the rest as usual
36
+ mov edx , 1
37
+ mov [ isNegativeAtoi ], edx ;change global variable
38
+
29
39
atoi_loop:
30
40
mov bl , [ eax ] ;get the character
31
41
test bl , bl ;check if we reached the end
@@ -42,7 +52,16 @@ atoi_loop:
42
52
43
53
end_of_atoi:
44
54
45
- mov eax , ecx ;return value
55
+ ;checking to see if the number was negative or not
56
+ mov eax , ecx
57
+ mov edx , [ isNegativeAtoi ]
58
+ cmp edx , 0
59
+ jz is_positive_number
60
+ ;we do the next only of the number is negative
61
+ mov eax , 0
62
+ sub eax , ecx
63
+ is_positive_number:
64
+
46
65
pop edx
47
66
pop ecx
48
67
pop ebx
@@ -84,8 +103,9 @@ check_if_operator: ;check is the symbol given parameter is an operator
84
103
;(+,-,*,/), store the information in "isOperator"
85
104
enter 0 , 0
86
105
87
- mov cl , [ ebp + 8 ]
88
- ;PRINTF32 `OPERATOR:%c:OPERATOR\n\x0`,ecx
106
+ mov ecx , [ ebp + 8 ] ;puttin into ecx the string
107
+ mov cl , [ ecx ] ;putting into cl the first character of the string
108
+
89
109
cmp cl , '+'
90
110
jz is_an_operator
91
111
cmp cl , '-'
@@ -99,6 +119,7 @@ check_if_operator: ;check is the symbol given parameter is an operator
99
119
jmp end
100
120
101
121
is_an_operator:
122
+ ;PRINTF32 `OPERATOR:%c:OPERATOR\n\x0`,ecx
102
123
mov ebx , 0x1
103
124
mov [ isOperator ], ebx
104
125
@@ -164,7 +185,7 @@ traverse_token:
164
185
push eax ;saving eax register
165
186
push ebx ;saving ebx register
166
187
push ecx ;saving ecx register (nu e neaparat momentan)
167
- push ebx ;pushing parameter
188
+ push edx ;pushing parameter
168
189
call check_if_operator
169
190
add esp , 0x4 ;removing parameter
170
191
pop ecx ;restoring ecx register
@@ -184,7 +205,7 @@ things_to_do_if_operator:
184
205
mov ecx , [ currentNode ] ;move to ecx the node
185
206
mov ecx , [ ecx + 0x4 ] ;move to ecx the left node address
186
207
cmp ecx , 0x0 ;check if it si null
187
- jz add_to_left
208
+ jz add_to_left_operator
188
209
jmp add_to_right_operator
189
210
; DONE
190
211
@@ -197,12 +218,14 @@ things_to_do_if_not_operator:
197
218
cmp ecx , 0x0 ;check if it si null
198
219
jz add_to_left_value
199
220
jmp add_to_right_value
221
+ ; DONE
200
222
201
223
end_of_operator_actions:
202
-
224
+ ;mov ecx, [ecx]
225
+ ;PRINTF32 `INLINE:%s:INLINE\n\x0`,ecx
203
226
jmp traverse_token ;iterate for next character
204
227
205
- add_to_left :
228
+ add_to_left_operator :
206
229
mov ecx , [ currentNode ] ;move to ecx the node
207
230
mov [ ecx + 0x4 ], eax ;left value is updated
208
231
mov [ currentNode ], eax ;currentNode is updated to the inserted value
@@ -219,12 +242,26 @@ add_to_left_value:
219
242
mov [ ecx + 0x4 ], eax ;left value is updated
220
243
jmp end_of_operator_actions ;TBDT
221
244
222
- add_to_right_value: ;adding to the right for integer values
245
+ add_to_right_value: ;adding to the right for integer values
223
246
mov ecx , [ currentNode ] ;move to ecx the node
224
247
mov [ ecx + 0x8 ], eax ;right value is updated
248
+
249
+ ;now currentNode becomes the value in the stack that has a free right spot
250
+ ;we are going to check for ecx, and when we find the value, we stop
251
+ loop_for_currentNode:
225
252
pop ecx ;pop the parrent node of value
226
- mov ecx , [ esp + 0x4 ] ;mov to ecx the future currentNode without poping
253
+ mov ecx , [ esp ] ;mov to ecx the future currentNode without poping
227
254
mov [ currentNode ], ecx ;update currentNode to future currentNode
255
+ ;now we test to see if currentNode(ecx) has a free right
256
+ mov ecx , [ ecx + 0x8 ] ;move to ecx the right value
257
+ cmp ecx , 0x0 ;check if right tree is null
258
+ jz we_have_found_currNode
259
+ jmp loop_for_currentNode
260
+
261
+ we_have_found_currNode:
262
+ ;mov ecx, [ecx]
263
+ ;PRINTF32 `INLINE:%s:INLINE\n\x0`,ecx
264
+
228
265
jmp end_of_operator_actions ;TBDT
229
266
230
267
reached_end_token:
@@ -241,6 +278,15 @@ loop_for_poping_remaining_nodes:
241
278
very_end:
242
279
mov eax , [ root ] ;put in eax the root
243
280
281
+ ;mov ecx, [eax + 4] ; left of "+"
282
+ ;mov ecx, [ecx + 4] ; right of "*"
283
+ ;mov ecx, [ecx + 4] ; right of "/"
284
+ ;mov ecx, [ecx + 4]
285
+ ;mov ecx, [ecx] ;
286
+
287
+
288
+ ;PRINTF32 `SFARSIT:%s:SFARSIT\n\x0`,ecx
289
+
244
290
pop edx
245
291
pop ecx
246
292
pop ebx
0 commit comments