-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.asm
375 lines (302 loc) · 10.6 KB
/
utilities.asm
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
.386
option casemap:none
.code
CreateControls proto, hWnd: HWND
aggiungiTestoNum proto, num: DWORD
cancellaTestoNum proto
stringToNum proto, lpStr: DWORD, lpNum: DWORD
potenza proto, base: DWORD, exp: DWORD
reversaStr proto, lpStr: DWORD
numToStr proto, num: DWORD, lpStr: DWORD
; ¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤
; AggiungiTestoNum
; ¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤
aggiungiTestoNum proc, num: DWORD
; aggiunge il numero 'num' alla fine del testo
; in txtNum
push edx
push esi
push eax
mov esi, offset buffer
invoke GetWindowText, txtNumWnd, addr buffer, 1023
push eax
invoke lstrcmp, addr buffer, addr txtNumText
jnz aggiungi_testo
xor edx, edx
mov [esi], edx
dec esi
aggiungi_testo:
pop eax
pop edx
add edx, 30h
add esi, eax
mov [esi], dx
pop esi
invoke SetWindowText, txtNumWnd, addr buffer
mov eax, edx
pop edx
ret
aggiungiTestoNum endp
; ¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤
; CancellaTestoNum
; ¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤
cancellaTestoNum proc
; cancella il primo numero di txtNum
; mette "0" se quello è l'unico numero
push eax
push esi
invoke GetWindowText, txtNumWnd, addr buffer, 1023
dec eax
jz tutto_cancellato
mov esi, offset buffer
add esi, eax
xor eax, eax
mov [esi], al
cancella_testo_num_imposta_testo:
invoke SetWindowText, txtNumWnd, addr buffer
pop esi
pop eax
ret
tutto_cancellato:
invoke lstrcpy, addr buffer, addr txtNumText
jmp cancella_testo_num_imposta_testo
cancellaTestoNum endp
; ¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤
; StringToNum
; ¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤
stringToNum proc, lpStr: DWORD, lpNum: DWORD
; converte la stringa puntata da lpStr
; in numero in base 10, salva il risultato
; nella var puntata da lpNum
push esi
push edi
push eax
push ebx
push ecx
push edx
invoke lstrcmp, addr txtNumText, lpStr
jz isZero_stringToNum
mov esi, lpStr
mov bl, [esi]
cmp bl, btnMenoText
jne stringToNum_positivo_1
mov esi, lpNum
xor ebx, ebx
dec ebx
mov [esi], ebx
inc lpStr
stringToNum_positivo_1:
invoke reversaStr, lpStr
invoke lstrlen, lpStr
xor ebx, ebx
dec eax
mov ecx, eax
mov esi, lpStr
add esi, eax
loop_str2num_calcola:
xor edx, edx
mov dl, [esi]
sub dl, 30h
invoke potenza, 0ah, ecx ; eax = 10 ^ ecx
mul dx ; eax *= dx
shl edx, 16
add eax, edx
add ebx, eax
dec esi
dec ecx
jns loop_str2num_calcola
mov esi, lpNum
mov eax, [esi]
cmp eax, 0ffffffffh
jne stringToNum_positivo_2
neg ebx
stringToNum_positivo_2:
mov [esi], ebx
fine_stringToNum:
pop edx
pop ecx
pop ebx
pop eax
pop edi
pop esi
ret
isZero_stringToNum:
mov ebx, lpNum
xor eax, eax
mov [ebx], eax
jmp fine_stringToNum
stringToNum endp
; ¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤
; ReversaStr
; ¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤
reversaStr proc, lpStr: DWORD
; reversa la stringa
; abcdef -> fedcba
push edi
push esi
push eax
push ecx
push edx
invoke lstrlen, lpStr
cmp eax, 1
jbe fine_reversaStr
dec eax
mov edi, lpStr
mov esi, edi
add edi, eax
dec edi
mov ecx, eax
mov edx, 2
shr ecx, 2
jnc loop_reversaStr
inc ecx
loop_reversaStr:
mov ax, word ptr [esi]
mov bx, word ptr [edi]
xchg al, ah
xchg bl, bh
mov word ptr [esi], bx
mov word ptr [edi], ax
add esi, edx
sub edi, edx
sub ecx, edx
cmp ecx, 0
jbe loop_reversaStr
fine_reversaStr:
pop edx
pop ecx
pop eax
pop esi
pop edi
ret
reversaStr endp
; ¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤
; Potenza
; ¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤
potenza proc, base: DWORD, exp: DWORD
; eax = base ^ exp
push ebx
push ecx
push edx
mov ecx, exp
cmp ecx, 0
jb exp_neg
mov ebx, base
cmp ebx, 0
jge continua
neg ebx
continua:
xor eax, eax
inc eax
cmp ecx, 0
je fine_potenza
loop_exp:
mul bx
shl edx, 16
add eax, edx
dec ecx
jnz loop_exp
fine_potenza:
pop edx
pop ecx
pop ebx
ret
exp_neg:
xor eax,eax
jmp fine_potenza
potenza endp
; ¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤
; NumToStr
; ¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤
numToStr proc, num:DWORD, lpStr: DWORD
; converte 'num' in stringa
; salvando il risultato in
; lpStr (char *)
push eax
push ebx
push ecx
push edx
push esi
mov eax, num
mov esi, lpStr
cmp eax, 0
jz isZero_numToStr
jg isPositivo_numToStr
mov bl, btnMenoText
mov [esi], bl
inc esi
neg eax
mov lpStr, esi
isPositivo_numToStr:
mov ebx, 0ah
mov ecx, 30h
strToNum_loop:
cmp eax, 0
je fine_divisione
xor edx, edx
jb fine_divisione
div bx
add edx, ecx
mov [esi], edx
inc esi
jmp strToNum_loop
isZero_numToStr:
invoke lstrcpy, lpStr, addr txtNumText
jmp tutto_finito_numToStr
fine_divisione:
invoke reversaStr, lpStr
tutto_finito_numToStr:
pop esi
pop edx
pop ecx
pop ebx
pop eax
ret
numToStr endp
; ¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤
; CreateControls
; ¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤
CreateControls proc, hWnd: HWND
; crea i controlli del form
invoke CreateWindowEx, NULL, addr buttonClassName, addr btnPerText, buttonStyle, 270, 155,buttonWidth, buttonHeight, hWnd, btnPerID, hInstance, NULL
mov btnPerWnd, eax
invoke CreateWindowEx, NULL, addr buttonClassName, addr btnDivisoText, buttonStyle, 270, 120, buttonWidth, buttonHeight, hWnd, btnDivisoID, hInstance, NULL
mov btnDivisoWnd, eax
invoke CreateWindowEx, NULL, addr buttonClassName, addr btnMenoText, buttonStyle, 270, 84, buttonWidth, buttonHeight, hWnd, btnMenoID, hInstance, NULL
mov btnMenoWnd, eax
invoke CreateWindowEx, NULL, addr buttonClassName, addr btnPiuText, buttonStyle, 270, 48, buttonWidth, buttonHeight, hWnd, btnPiuID, hInstance, NULL
mov btnPiuWnd, eax
invoke CreateWindowEx, NULL, addr buttonClassName, addr btnUgualeText, buttonStyle, 270, 12, buttonWidth, buttonHeight, hWnd, btnUgualeID, hInstance, NULL
mov btnUgualeWnd, eax
invoke CreateWindowEx, NULL, addr buttonClassName, addr btn0Text, buttonStyle, 96, 160, buttonWidth, buttonHeight, hWnd, btn0ID, hInstance, NULL
mov btn0Wnd, eax
invoke CreateWindowEx, NULL, addr buttonClassName, addr btn1Text, buttonStyle, 12, 48, buttonWidth, buttonHeight, hWnd, btn1ID, hInstance, NULL
mov btn1Wnd, eax
invoke CreateWindowEx, NULL, addr buttonClassName, addr btn2Text, buttonStyle, 96, 48, buttonWidth, buttonHeight, hWnd, btn2ID, hInstance, NULL
mov btn2Wnd, eax
invoke CreateWindowEx, NULL, addr buttonClassName, addr btn3Text, buttonStyle, 180, 48, buttonWidth, buttonHeight, hWnd, btn3ID, hInstance, NULL
mov btn3Wnd, eax
invoke CreateWindowEx, NULL, addr buttonClassName, addr btn4Text, buttonStyle, 12, 84, buttonWidth, buttonHeight, hWnd, btn4ID, hInstance, NULL
mov btn4Wnd, eax
invoke CreateWindowEx, NULL, addr buttonClassName, addr btn5Text, buttonStyle, 96, 84, buttonWidth, buttonHeight, hWnd, btn5ID, hInstance, NULL
mov btn5Wnd, eax
invoke CreateWindowEx, NULL, addr buttonClassName, addr btn6Text, buttonStyle, 180, 84, buttonWidth, buttonHeight, hWnd, btn6ID, hInstance, NULL
mov btn6Wnd, eax
invoke CreateWindowEx, NULL, addr buttonClassName, addr btn7Text, buttonStyle, 12, 120, buttonWidth, buttonHeight, hWnd, btn7ID, hInstance, NULL
mov btn7Wnd, eax
invoke CreateWindowEx, NULL, addr buttonClassName, addr btn8Text, buttonStyle, 96, 120, buttonWidth, buttonHeight, hWnd, btn8ID, hInstance, NULL
mov btn8Wnd, eax
invoke CreateWindowEx, NULL, addr buttonClassName, addr btn9Text, buttonStyle, 180, 120, buttonWidth, buttonHeight, hWnd, btn9ID, hInstance, NULL
mov btn9Wnd, eax
invoke CreateWindowEx, NULL, addr buttonClassName, addr btnClearText, buttonStyle, 12, 160, buttonWidth, buttonHeight, hWnd, btnClearID, hInstance, NULL
mov btnClearWnd, eax
invoke CreateWindowEx, NULL, addr buttonClassName, addr btnCancText, buttonStyle, 180, 160, buttonWidth, buttonHeight, hWnd, btnCancID, hInstance, NULL
mov btnCancWnd, eax
invoke CreateWindowEx, NULL, addr buttonClassName, addr btnSegnoText, buttonStyle, 180, 196, buttonWidth, buttonHeight, hWnd, btnSegnoID, hInstance, NULL
mov btnSegnoWnd, eax
invoke CreateWindowEx, NULL, addr buttonClassName, addr btnPotenzaText, buttonStyle, 96, 196, buttonWidth, buttonHeight, hWnd, btnPotenzaID, hInstance, NULL
mov btnPotenzaWnd, eax
invoke CreateWindowEx, NULL, addr editClassName, addr txtNumText, buttonStyle or ES_NUMBER or WS_BORDER or ES_RIGHT, 12, 12, 243, 30, hWnd, txtNumID, hInstance, NULL
mov txtNumWnd, eax
ret
CreateControls endp