@@ -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,12 +103,13 @@ 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 eax , [ ebp + 8 ] ;puttin into ecx the string
107
+ mov cl , [ eax ] ;putting into cl the first character of the string
108
+
89
109
cmp cl , '+'
90
110
jz is_an_operator
91
111
cmp cl , '-'
92
- jz is_an_operator
112
+ jz is_a_minus ;it could either a operator or a negative number
93
113
cmp cl , '*'
94
114
jz is_an_operator
95
115
cmp cl , '/'
@@ -98,11 +118,21 @@ check_if_operator: ;check is the symbol given parameter is an operator
98
118
mov [ isOperator ], ebx
99
119
jmp end
100
120
121
+ is_a_minus:
122
+ mov cl , [ eax + 0x1 ] ;get the second character
123
+ cmp cl , 0 ;if the next char is '\0' is an operator
124
+ jz is_an_operator
125
+ mov ebx , 0x0 ; it is not an operator
126
+ mov [ isOperator ], ebx
127
+ jmp end
128
+
101
129
is_an_operator:
130
+ ;PRINTF32 `OPERATOR:%c:OPERATOR\n\x0`,ecx
102
131
mov ebx , 0x1
103
132
mov [ isOperator ], ebx
104
133
105
134
end:
135
+
106
136
leave
107
137
ret
108
138
@@ -151,6 +181,12 @@ traverse_token:
151
181
152
182
;PRINTF32 `DA:%s:DA\n\x0`,edx
153
183
184
+ ;push ecx
185
+ ;mov ecx, [currentNode]
186
+ ;mov ecx, [ecx]
187
+ ;PRINTF32 `INLINE:%s:INLINE\n\x0`,ecx
188
+ ;pop ecx
189
+
154
190
push ebx ;saving ebx register
155
191
push ecx ;saving ecx register
156
192
push edx ;saving edx register
@@ -164,7 +200,7 @@ traverse_token:
164
200
push eax ;saving eax register
165
201
push ebx ;saving ebx register
166
202
push ecx ;saving ecx register (nu e neaparat momentan)
167
- push ebx ;pushing parameter
203
+ push edx ;pushing parameter
168
204
call check_if_operator
169
205
add esp , 0x4 ;removing parameter
170
206
pop ecx ;restoring ecx register
@@ -184,7 +220,7 @@ things_to_do_if_operator:
184
220
mov ecx , [ currentNode ] ;move to ecx the node
185
221
mov ecx , [ ecx + 0x4 ] ;move to ecx the left node address
186
222
cmp ecx , 0x0 ;check if it si null
187
- jz add_to_left
223
+ jz add_to_left_operator
188
224
jmp add_to_right_operator
189
225
; DONE
190
226
@@ -197,12 +233,13 @@ things_to_do_if_not_operator:
197
233
cmp ecx , 0x0 ;check if it si null
198
234
jz add_to_left_value
199
235
jmp add_to_right_value
236
+ ; DONE
200
237
201
238
end_of_operator_actions:
202
239
203
240
jmp traverse_token ;iterate for next character
204
241
205
- add_to_left :
242
+ add_to_left_operator :
206
243
mov ecx , [ currentNode ] ;move to ecx the node
207
244
mov [ ecx + 0x4 ], eax ;left value is updated
208
245
mov [ currentNode ], eax ;currentNode is updated to the inserted value
@@ -219,12 +256,24 @@ add_to_left_value:
219
256
mov [ ecx + 0x4 ], eax ;left value is updated
220
257
jmp end_of_operator_actions ;TBDT
221
258
222
- add_to_right_value: ;adding to the right for integer values
259
+ add_to_right_value: ;adding to the right for integer values
223
260
mov ecx , [ currentNode ] ;move to ecx the node
224
261
mov [ ecx + 0x8 ], eax ;right value is updated
262
+
263
+ ;now currentNode becomes the value in the stack that has a free right spot
264
+ ;we are going to check for ecx, and when we find the value, we stop
265
+ loop_for_currentNode:
225
266
pop ecx ;pop the parrent node of value
226
- mov ecx , [ esp + 0x4 ] ;mov to ecx the future currentNode without poping
267
+ mov ecx , [ esp ] ;mov to ecx the future currentNode without poping
227
268
mov [ currentNode ], ecx ;update currentNode to future currentNode
269
+ ;now we test to see if currentNode(ecx) has a free right
270
+ mov ecx , [ ecx + 0x8 ] ;move to ecx the right value
271
+ cmp ecx , 0x0 ;check if right tree is null
272
+ jz we_have_found_currNode
273
+ jmp loop_for_currentNode
274
+
275
+ we_have_found_currNode:
276
+
228
277
jmp end_of_operator_actions ;TBDT
229
278
230
279
reached_end_token:
@@ -241,6 +290,15 @@ loop_for_poping_remaining_nodes:
241
290
very_end:
242
291
mov eax , [ root ] ;put in eax the root
243
292
293
+ ;mov ecx, [eax + 0x8] ; left of "+"
294
+ ;mov ecx, [ecx + 0x4] ; right of "*"
295
+ ;mov ecx, [ecx + 4] ; right of "/"
296
+ ;mov ecx, [ecx + 4]
297
+ ;mov ecx, [ecx] ;
298
+
299
+
300
+ ;PRINTF32 `SFARSIT:%s:SFARSIT\n\x0`,ecx
301
+
244
302
pop edx
245
303
pop ecx
246
304
pop ebx
0 commit comments