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
|
; Static Name Aliases
;
TITLE bn_mulw.c
.386
F_TEXT SEGMENT WORD USE16 PUBLIC 'CODE'
F_TEXT ENDS
_DATA SEGMENT WORD USE16 PUBLIC 'DATA'
_DATA ENDS
CONST SEGMENT WORD USE16 PUBLIC 'CONST'
CONST ENDS
_BSS SEGMENT WORD USE16 PUBLIC 'BSS'
_BSS ENDS
DGROUP GROUP CONST, _BSS, _DATA
ASSUME DS: DGROUP, SS: DGROUP
F_TEXT SEGMENT
ASSUME CS: F_TEXT
PUBLIC _bn_mul_add_words
_bn_mul_add_words PROC FAR
; Line 58
push bp
push bx
push esi
push di
push ds
push es
mov bp,sp
; w = 28
; num = 26
; ap = 22
; rp = 18
xor esi,esi ;c=0;
mov di,WORD PTR [bp+18] ; load r
mov ds,WORD PTR [bp+20] ; load r
mov bx,WORD PTR [bp+22] ; load a
mov es,WORD PTR [bp+24] ; load a
mov ecx,DWORD PTR [bp+28] ; load w
mov bp,WORD PTR [bp+26] ; load num
shr bp,1 ; div count by 4 and do groups of 4
shr bp,1
je $L555
$L546:
mov eax,ecx
mul DWORD PTR es:[bx] ; w* *a
add eax,DWORD PTR ds:[di] ; + *r
adc edx,0
adc eax,esi
adc edx,0
mov DWORD PTR ds:[di],eax
mov esi,edx
;
mov eax,ecx
mul DWORD PTR es:[bx+4] ; w* *a
add eax,DWORD PTR ds:[di+4] ; + *r
adc edx,0
adc eax,esi
adc edx,0
mov DWORD PTR ds:[di+4],eax
mov esi,edx
;
mov eax,ecx
mul DWORD PTR es:[bx+8] ; w* *a
add eax,DWORD PTR ds:[di+8] ; + *r
adc edx,0
adc eax,esi
adc edx,0
mov DWORD PTR ds:[di+8],eax
mov esi,edx
;
mov eax,ecx
mul DWORD PTR es:[bx+12] ; w* *a
add eax,DWORD PTR ds:[di+12] ; + *r
adc edx,0
adc eax,esi
adc edx,0
mov DWORD PTR ds:[di+12],eax
mov esi,edx
;
add bx,16
add di,16
;
dec bp
je $L555
jmp $L546
;
;
$L555:
mov bp,sp
mov bp,WORD PTR [bp+26] ; load num
and bp,3
dec bp
js $L547
mov eax,ecx
mul DWORD PTR es:[bx] ; w* *a
add eax,DWORD PTR ds:[di] ; + *r
adc edx,0
adc eax,esi
adc edx,0
mov DWORD PTR ds:[di],eax
mov esi,edx
dec bp
js $L547 ; Note that we are now testing for -1
;
mov eax,ecx
mul DWORD PTR es:[bx+4] ; w* *a
add eax,DWORD PTR ds:[di+4] ; + *r
adc edx,0
adc eax,esi
adc edx,0
mov DWORD PTR ds:[di+4],eax
mov esi,edx
dec bp
js $L547
;
mov eax,ecx
mul DWORD PTR es:[bx+8] ; w* *a
add eax,DWORD PTR ds:[di+8] ; + *r
adc edx,0
adc eax,esi
adc edx,0
mov DWORD PTR ds:[di+8],eax
mov esi,edx
$L547:
mov eax,esi
mov edx,esi
shr edx,16
pop es
pop ds
pop di
pop esi
pop bx
pop bp
ret
nop
_bn_mul_add_words ENDP
PUBLIC _bn_mul_words
_bn_mul_words PROC FAR
; Line 76
push bp
push bx
push esi
push di
push ds
push es
xor esi,esi
mov bp,sp
mov di,WORD PTR [bp+18] ; r
mov ds,WORD PTR [bp+20]
mov bx,WORD PTR [bp+22] ; a
mov es,WORD PTR [bp+24]
mov ecx,DWORD PTR [bp+28] ; w
mov bp,WORD PTR [bp+26] ; num
$FC743:
mov eax,ecx
mul DWORD PTR es:[bx]
add eax,esi
adc edx,0
mov DWORD PTR ds:[di],eax
mov esi,edx
dec bp
je $L764
;
mov eax,ecx
mul DWORD PTR es:[bx+4]
add eax,esi
adc edx,0
mov DWORD PTR ds:[di+4],eax
mov esi,edx
dec bp
je $L764
;
mov eax,ecx
mul DWORD PTR es:[bx+8]
add eax,esi
adc edx,0
mov DWORD PTR ds:[di+8],eax
mov esi,edx
dec bp
je $L764
;
mov eax,ecx
mul DWORD PTR es:[bx+12]
add eax,esi
adc edx,0
mov DWORD PTR ds:[di+12],eax
mov esi,edx
dec bp
je $L764
;
add bx,16
add di,16
jmp $FC743
nop
$L764:
mov eax,esi
mov edx,esi
shr edx,16
pop es
pop ds
pop di
pop esi
pop bx
pop bp
ret
nop
_bn_mul_words ENDP
PUBLIC _bn_sqr_words
_bn_sqr_words PROC FAR
; Line 92
push bp
push bx
push si
push di
push ds
push es
mov bp,sp
mov si,WORD PTR [bp+16]
mov ds,WORD PTR [bp+18]
mov di,WORD PTR [bp+20]
mov es,WORD PTR [bp+22]
mov bx,WORD PTR [bp+24]
mov bp,bx ; save a memory lookup later
shr bx,1 ; div count by 4 and do groups of 4
shr bx,1
je $L666
$L765:
mov eax,DWORD PTR es:[di]
mul eax
mov DWORD PTR ds:[si],eax
mov DWORD PTR ds:[si+4],edx
;
mov eax,DWORD PTR es:[di+4]
mul eax
mov DWORD PTR ds:[si+8],eax
mov DWORD PTR ds:[si+12],edx
;
mov eax,DWORD PTR es:[di+8]
mul eax
mov DWORD PTR ds:[si+16],eax
mov DWORD PTR ds:[si+20],edx
;
mov eax,DWORD PTR es:[di+12]
mul eax
mov DWORD PTR ds:[si+24],eax
mov DWORD PTR ds:[si+28],edx
;
add di,16
add si,32
dec bx
je $L666
jmp $L765
$L666:
and bp,3
dec bp ; The copied value of bx (num)
js $L645
;
mov eax,DWORD PTR es:[di]
mul eax
mov DWORD PTR ds:[si],eax
mov DWORD PTR ds:[si+4],edx
dec bp
js $L645
;
mov eax,DWORD PTR es:[di+4]
mul eax
mov DWORD PTR ds:[si+8],eax
mov DWORD PTR ds:[si+12],edx
dec bp
js $L645
;
mov eax,DWORD PTR es:[di+8]
mul eax
mov DWORD PTR ds:[si+16],eax
mov DWORD PTR ds:[si+20],edx
$L645:
pop es
pop ds
pop di
pop si
pop bx
pop bp
ret
_bn_sqr_words ENDP
PUBLIC _bn_div64
_bn_div64 PROC FAR
push bp
mov bp,sp
mov edx, DWORD PTR [bp+6]
mov eax, DWORD PTR [bp+10]
div DWORD PTR [bp+14]
mov edx,eax
shr edx,16
pop bp
ret
_bn_div64 ENDP
PUBLIC _bn_add_words
_bn_add_words PROC FAR
; Line 58
push bp
push bx
push esi
push di
push ds
push es
mov bp,sp
; w = 28
; num = 26
; ap = 22
; rp = 18
xor esi,esi ;c=0;
mov si,WORD PTR [bp+22] ; load a
mov es,WORD PTR [bp+24] ; load a
mov di,WORD PTR [bp+26] ; load b
mov ds,WORD PTR [bp+28] ; load b
mov dx,WORD PTR [bp+30] ; load num
dec dx
js $L547
xor ecx,ecx
$L5477:
xor ebx,ebx
mov eax,DWORD PTR es:[si] ; *a
add eax,ecx
adc ebx,0
add si,4 ; a++
add eax,DWORD PTR ds:[di] ; + *b
mov ecx,ebx
adc ecx,0
add di,4
mov bx,WORD PTR [bp+18]
mov ds,WORD PTR [bp+20]
mov DWORD PTR ds:[bx],eax
add bx,4
mov ds,WORD PTR [bp+28]
mov WORD PTR [bp+18],bx
dec dx
js $L547 ; Note that we are now testing for -1
jmp $L5477
;
$L547:
mov eax,ecx
mov edx,ecx
shr edx,16
pop es
pop ds
pop di
pop esi
pop bx
pop bp
ret
nop
_bn_add_words ENDP
F_TEXT ENDS
END
|