@@ -3,9 +3,9 @@ section .data
3
3
4
4
section .bss
5
5
root resd 1
6
- currentNode resd 1
7
- isOperator resd 1
8
- isNegativeAtoi resd 1
6
+ current_node resd 1
7
+ is_operator resd 1
8
+ is_negative_atoi resd 1
9
9
10
10
section .text
11
11
@@ -20,21 +20,19 @@ global iocla_atoi
20
20
iocla_atoi: ;change string to number
21
21
enter 0 , 0
22
22
push ebx ;saving callee registers
23
- push ecx
24
- push edx
25
23
26
24
mov eax , [ ebp + 8 ]
27
25
xor ecx , ecx ;stores the result
28
26
xor ebx , ebx ;stores character
29
27
30
28
mov edx , 0
31
- mov [ isNegativeAtoi ], edx ;the default way is that the number is positive
29
+ mov [ is_negative_atoi ], edx ;the default way is that the number is positive
32
30
;we check to see if the number is negative or not
33
31
mov bl , [ eax ]
34
32
cmp bl , '-' ;compare to minus character
35
33
jnz atoi_loop ;if it is not a minus sign just do the rest as usual
36
34
mov edx , 1
37
- mov [ isNegativeAtoi ], edx ;change global variable
35
+ mov [ is_negative_atoi ], edx ;change global variable
38
36
inc eax ;get rid of the minus
39
37
40
38
atoi_loop:
@@ -51,17 +49,15 @@ end_of_atoi:
51
49
52
50
;checking to see if the number was negative or not
53
51
mov eax , ecx
54
- mov edx , [ isNegativeAtoi ]
52
+ mov edx , [ is_negative_atoi ]
55
53
cmp edx , 0
56
54
jz is_positive_number
57
55
;we do the next only of the number is negative
58
56
mov eax , 0
59
57
sub eax , ecx
60
58
is_positive_number:
61
59
62
- pop edx ;restoring callee registers
63
- pop ecx
64
- pop ebx
60
+ pop ebx ;restoring callee registers
65
61
leave
66
62
ret
67
63
@@ -74,7 +70,7 @@ replace_next_white_char: ;replaces next space character with '\0'
74
70
75
71
starting_loop:
76
72
mov cl , [ ebx ]
77
- cmp cl , ' '
73
+ cmp cl , [ delim ]
78
74
jz end_of_replacement ;we have found a space, going to replace it
79
75
cmp cl , 0
80
76
jz last_word_case ;we have foudn a '\0' char, this is the last word
@@ -96,7 +92,7 @@ end_of_replacement_function:
96
92
ret
97
93
98
94
check_if_operator: ;check is the symbol given parameter is an operator
99
- ;(+,-,*,/), store the information in "isOperator "
95
+ ;(+,-,*,/), store the information in "is_operator "
100
96
enter 0 , 0
101
97
push ebx
102
98
@@ -112,20 +108,20 @@ check_if_operator: ;check is the symbol given parameter is an operator
112
108
cmp cl , '/'
113
109
jz is_an_operator
114
110
mov ebx , 0x0 ; it is not an operator
115
- mov [ isOperator ], ebx
111
+ mov [ is_operator ], ebx
116
112
jmp end
117
113
118
114
is_a_minus:
119
115
mov cl , [ eax + 0x1 ] ;get the second character
120
116
cmp cl , 0 ;if the next char is '\0' is an operator
121
117
jz is_an_operator
122
118
mov ebx , 0x0 ; it is not an operator
123
- mov [ isOperator ], ebx
119
+ mov [ is_operator ], ebx
124
120
jmp end
125
121
126
122
is_an_operator:
127
123
mov ebx , 0x1
128
- mov [ isOperator ], ebx
124
+ mov [ is_operator ], ebx
129
125
130
126
end:
131
127
136
132
create_tree:
137
133
enter 0 , 0
138
134
push ebx ;saving registers
139
- push ecx
140
- push edx
141
135
142
136
mov edx , [ ebp + 8 ]
143
137
@@ -178,7 +172,7 @@ create_tree:
178
172
pop ebx ;restoring ebx register
179
173
180
174
mov [ root ], eax ; ;initialize the root
181
- mov [ currentNode ], eax ;initialize the currentNode for the first time
175
+ mov [ current_node ], eax ;initialize the current_node for the first time
182
176
push eax ; ;push first node to stack
183
177
184
178
traverse_token:
@@ -231,17 +225,17 @@ traverse_token:
231
225
pop ebx ;restoring ebx register
232
226
pop eax ;restoring eax register
233
227
234
- mov ecx , [ isOperator ] ;
228
+ mov ecx , [ is_operator ] ;
235
229
cmp ecx , 0x1
236
230
je things_to_do_if_operator ;it is an operator
237
231
jmp things_to_do_if_not_operator ;it is not an operator
238
232
239
233
things_to_do_if_operator:
240
234
push eax
241
- ;now we add the eax node either to the left or right of currentNode
235
+ ;now we add the eax node either to the left or right of current_node
242
236
;if left is null, add to left; if left is not null, add to right and change
243
- ;currentNode to parrent node
244
- mov ecx , [ currentNode ] ;move to ecx the node
237
+ ;current_node to parrent node
238
+ mov ecx , [ current_node ] ;move to ecx the node
245
239
mov ecx , [ ecx + 0x4 ] ;move to ecx the left node address
246
240
cmp ecx , 0x0 ;check if it si null
247
241
jz add_to_left_operator
@@ -251,8 +245,8 @@ things_to_do_if_operator:
251
245
things_to_do_if_not_operator:
252
246
;NO need to push eax because integer values are always leafs
253
247
;we add the eax node either to the left or right, if we add to the right
254
- ;the currentNode is updated by poping the stack
255
- mov ecx , [ currentNode ] ;move to ecx the node
248
+ ;the current_node is updated by poping the stack
249
+ mov ecx , [ current_node ] ;move to ecx the node
256
250
mov ecx , [ ecx + 0x4 ] ;move to ecx the left node address
257
251
cmp ecx , 0x0 ;check if it si null
258
252
jz add_to_left_value
@@ -264,58 +258,56 @@ end_of_operator_actions:
264
258
jmp traverse_token ;iterate for next character
265
259
266
260
add_to_left_operator:
267
- mov ecx , [ currentNode ] ;move to ecx the node
261
+ mov ecx , [ current_node ] ;move to ecx the node
268
262
mov [ ecx + 0x4 ], eax ;left value is updated
269
- mov [ currentNode ], eax ;currentNode is updated to the inserted value
263
+ mov [ current_node ], eax ;current_node is updated to the inserted value
270
264
jmp end_of_operator_actions ;TBDT
271
265
272
266
add_to_right_operator: ;adding to the right for operators
273
- mov ecx , [ currentNode ] ;move to ecx the node
267
+ mov ecx , [ current_node ] ;move to ecx the node
274
268
mov [ ecx + 0x8 ], eax ;right value is updated
275
- mov [ currentNode ], eax ;currentNode is updated to the inserted value
269
+ mov [ current_node ], eax ;current_node is updated to the inserted value
276
270
jmp end_of_operator_actions ;TBDT
277
271
278
272
add_to_left_value:
279
- mov ecx , [ currentNode ] ;move to ecx the node
273
+ mov ecx , [ current_node ] ;move to ecx the node
280
274
mov [ ecx + 0x4 ], eax ;left value is updated
281
275
jmp end_of_operator_actions ;TBDT
282
276
283
277
add_to_right_value: ;adding to the right for integer values
284
- mov ecx , [ currentNode ] ;move to ecx the node
278
+ mov ecx , [ current_node ] ;move to ecx the node
285
279
mov [ ecx + 0x8 ], eax ;right value is updated
286
280
287
- ;now currentNode becomes the value in the stack that has a free right spot
281
+ ;now current_node becomes the value in the stack that has a free right spot
288
282
;we are going to check for ecx, and when we find the value, we stop
289
- loop_for_currentNode :
283
+ loop_for_current_node :
290
284
pop ecx ;pop the parrent node of value
291
- mov ecx , [ esp ] ;mov to ecx the future currentNode without poping
292
- mov [ currentNode ], ecx ;update currentNode to future currentNode
293
- ;now we test to see if currentNode (ecx) has a free right
285
+ mov ecx , [ esp ] ;mov to ecx the future current_node without poping
286
+ mov [ current_node ], ecx ;update current_node to future current_node
287
+ ;now we test to see if current_node (ecx) has a free right
294
288
mov ecx , [ ecx + 0x8 ] ;move to ecx the right value
295
289
cmp ecx , 0x0 ;check if right tree is null
296
290
jz we_have_found_currNode
297
- jmp loop_for_currentNode
291
+ jmp loop_for_current_node
298
292
299
293
we_have_found_currNode:
300
294
301
295
jmp end_of_operator_actions ;TBDT
302
296
303
297
reached_end_token:
304
298
;now we should pop the remaining stack nodes that we have pushed
305
- ;we pop everytime into the currentNode and do that until currentNode = ebp
299
+ ;we pop everytime into the current_node and do that until current_node = ebp
306
300
307
301
loop_for_poping_remaining_nodes:
308
302
mov ecx , ebp
309
303
sub ecx , esp
310
- sub ecx , 0xc
304
+ sub ecx , 0x4
311
305
jz very_end ;reached the bottom of the stack, the frame pointer
312
306
add esp , 0x4 ;pop node into ecx (we do nothing with it)
313
307
314
308
very_end:
315
309
mov eax , [ root ] ;put in eax the root
316
310
317
- pop edx ;restoring registers
318
- pop ecx
319
311
pop ebx
320
312
leave
321
313
ret
0 commit comments