-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFASM.asm
441 lines (391 loc) · 7.76 KB
/
FASM.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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
; flat assembler interface for SELG
; Copyright (c) 1999-2019, Tomasz Grysztar.
; All rights reserved.
; adapté par Nicolas Leprince-Granger
pile equ 4096 ;definition de la taille de la pile
include "../../PROG/fe.inc"
db "Compilateur FASM"
scode:
org 0
;données du segment CS
mov ax,sel_dat1
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
mov esi,_logo
call display_string
call get_params
jc information
mov dword[stack_limit],pile
mov dword[additional_memory],sdata2
mov ecx,[memory_setting] ;mémoir a uttiliser en Ko
shl ecx,10
jnz allocate_memory
mov ecx,1000000h
allocate_memory:
mov eax,8
add ecx,[additional_memory]
mov dx,sel_dat1
int 61h
mov [memory_end],ecx
sub ecx,[additional_memory]
shr ecx,2
add ecx,[additional_memory]
mov [additional_memory_end],ecx
mov [memory_start],ecx
mov esi,_memory_prefix
call display_string
mov eax,[memory_end]
sub eax,[memory_start]
add eax,[additional_memory_end]
sub eax,[additional_memory]
shr eax,10
call display_number
mov esi,_memory_suffix
call display_string
call make_timestamp
mov [start_time],eax
and [preprocessing_done],0
call preprocessor
or [preprocessing_done],-1
call parser
call assembler
call formatter
call display_user_messages
movzx eax,[current_pass]
inc eax
call display_number
mov esi,_passes_suffix
call display_string
call make_timestamp
sub eax,[start_time]
; jnc time_ok
; add eax,3600000
; time_ok:
xor edx,edx
mov ebx,400
div ebx
or eax,eax
jz display_bytes_count
xor edx,edx
mov ebx,10
div ebx
push edx
call display_number
mov dl,'.'
call display_character
pop eax
call display_number
mov esi,_seconds_suffix
call display_string
display_bytes_count:
mov eax,[written_size]
call display_number
mov esi,_bytes_suffix
call display_string
xor al,al
jmp exit_program
;*********************************************
information:
mov esi,_usage
call display_string
mov al,1
jmp exit_program
;*********************************************
get_params:
mov [input_file],0
mov [output_file],0
mov [symbols_file],0
mov [memory_setting],0
mov [passes_limit],100
mov eax,3
mov edx,commande
int 61h
mov [definitions_pointer],predefinitions
mov esi,commande
mov edi,params
find_command_start:
lodsb
cmp al,20h
je find_command_start
cmp al,22h
je skip_quoted_name
skip_name:
lodsb
cmp al,20h
je find_param
or al,al
jz all_params
jmp skip_name
skip_quoted_name:
lodsb
cmp al,22h
je find_param
or al,al
jz all_params
jmp skip_quoted_name
find_param:
lodsb
cmp al,20h
je find_param
cmp al,'-'
je option_param
cmp al,0Dh
je all_params
or al,al
jz all_params
cmp [input_file],0
jne get_output_file
mov [input_file],edi
jmp process_param
get_output_file:
cmp [output_file],0
jne bad_params
mov [output_file],edi
process_param:
cmp al,22h
je string_param
copy_param:
cmp edi,params+1000h
jae bad_params
stosb
lodsb
cmp al,20h
je param_end
cmp al,0Dh
je param_end
or al,al
jz param_end
jmp copy_param
string_param:
lodsb
cmp al,22h
je string_param_end
cmp al,0Dh
je param_end
or al,al
jz param_end
cmp edi,params+1000h
jae bad_params
stosb
jmp string_param
option_param:
lodsb
cmp al,'m'
je memory_option
cmp al,'M'
je memory_option
cmp al,'p'
je passes_option
cmp al,'P'
je passes_option
cmp al,'d'
je definition_option
cmp al,'D'
je definition_option
cmp al,'s'
je symbols_option
cmp al,'S'
je symbols_option
bad_params:
stc
ret
get_option_value:
xor eax,eax
mov edx,eax
get_option_digit:
lodsb
cmp al,20h
je option_value_ok
cmp al,0Dh
je option_value_ok
or al,al
jz option_value_ok
sub al,30h
jc invalid_option_value
cmp al,9
ja invalid_option_value
imul edx,10
jo invalid_option_value
add edx,eax
jc invalid_option_value
jmp get_option_digit
option_value_ok:
dec esi
clc
ret
invalid_option_value:
stc
ret
memory_option:
lodsb
cmp al,20h
je memory_option
cmp al,0Dh
je bad_params
or al,al
jz bad_params
dec esi
call get_option_value
or edx,edx
jz bad_params
cmp edx,1 shl (32-10)
jae bad_params
mov [memory_setting],edx
jmp find_param
passes_option:
lodsb
cmp al,20h
je passes_option
cmp al,0Dh
je bad_params
or al,al
jz bad_params
dec esi
call get_option_value
or edx,edx
jz bad_params
cmp edx,10000h
ja bad_params
mov [passes_limit],dx
jmp find_param
definition_option:
lodsb
cmp al,20h
je definition_option
cmp al,0Dh
je bad_params
or al,al
jz bad_params
dec esi
push edi
mov edi,[definitions_pointer]
call convert_definition_option
mov [definitions_pointer],edi
pop edi
jc bad_params
jmp find_param
symbols_option:
mov [symbols_file],edi
find_symbols_file_name:
lodsb
cmp al,20h
jne process_param
jmp find_symbols_file_name
param_end:
dec esi
string_param_end:
cmp edi,params+1000h
jae bad_params
xor al,al
stosb
jmp find_param
all_params:
cmp [input_file],0
je bad_params
mov eax,[definitions_pointer]
mov byte [eax],0
mov [initial_definitions],predefinitions
clc
ret
convert_definition_option:
mov ecx,edi
cmp edi,predefinitions+1000h
jae bad_definition_option
xor al,al
stosb
copy_definition_name:
lodsb
cmp al,'='
je copy_definition_value
cmp al,20h
je bad_definition_option
cmp al,0Dh
je bad_definition_option
or al,al
jz bad_definition_option
cmp edi,predefinitions+1000h
jae bad_definition_option
stosb
inc byte [ecx]
jnz copy_definition_name
bad_definition_option:
stc
ret
copy_definition_value:
lodsb
cmp al,20h
je definition_value_end
cmp al,0Dh
je definition_value_end
or al,al
jz definition_value_end
cmp al,'\'
jne definition_value_character
cmp byte [esi],20h
jne definition_value_character
lodsb
definition_value_character:
cmp edi,predefinitions+1000h
jae bad_definition_option
stosb
jmp copy_definition_value
definition_value_end:
dec esi
cmp edi,predefinitions+1000h
jae bad_definition_option
xor al,al
stosb
clc
ret
include '..\errors.inc'
include '..\symbdump.inc'
include '..\preproce.inc'
include '..\parser.inc'
include '..\exprpars.inc'
include '..\assemble.inc'
include '..\exprcalc.inc'
include '..\formats.inc'
include '..\x86_64.inc'
include '..\avx.inc'
include 'system.inc'
include '..\messages.inc'
include '..\tables.inc'
include '..\variable.inc'
include '..\version.inc'
_copyright db 'Copyright (c) 1999-2019, Tomasz Grysztar',13,0
_logo db 'flat assembler version ',VERSION_STRING,0
_usage db 13
db 'usage: fasm <source> [output]',13
db 'optional settings:',13
db ' -m <limit> set the limit in kilobytes for the available memory',13
db ' -p <limit> set the maximum allowed number of passes',13
db ' -d <name>=<value> define symbolic variable',13
db ' -s <file> dump symbolic information for debugging',13,0
_memory_prefix db ' (',0
_memory_suffix db ' kilobytes memory)',13,0
_passes_suffix db ' passes, ',0
_seconds_suffix db ' seconds, ',0
_bytes_suffix db ' bytes.',13,0
command_line dd ?
memory_setting dd ?
definitions_pointer dd ?
environment dd ?
start_time dd ?
displayed_count dd ?
last_displayed db ?
character dw ?
preprocessing_done db ?
predefinitions rb 1000h
params rb 1000h
sdata2:
org 0
;données du segment ES
sdata3:
org 0
;données du segment FS
sdata4:
org 0
;données du segment GS
findata: