"Fossies" - the Fresh Open Source Software Archive 
Member "fasm/source/libc/fasm.asm" (21 Feb 2022, 6519 Bytes) of package /linux/misc/fasm-1.73.30.tgz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Generic Assembler source code syntax highlighting (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the latest
Fossies "Diffs" side-by-side code changes report for "fasm.asm":
1.73.29_vs_1.73.30.
1
2 ; flat assembler interface for Unix/libc
3 ; Copyright (c) 1999-2022, Tomasz Grysztar.
4 ; All rights reserved.
5
6 format ELF
7 public main
8
9 macro ccall proc,[arg]
10 { common
11 local size
12 size = 0
13 mov ebp,esp
14 if ~ arg eq
15 forward
16 size = size + 4
17 common
18 sub esp,size
19 end if
20 and esp,-16
21 if ~ arg eq
22 add esp,size
23 reverse
24 pushd arg
25 common
26 end if
27 call proc
28 mov esp,ebp }
29
30 extrn gettimeofday
31
32 section '.text' executable align 16
33
34 main:
35 mov ecx,[esp+4]
36 mov [argc],ecx
37 mov ebx,[esp+8]
38 mov [argv],ebx
39 push ebp
40 mov [stack_frame],esp
41
42 mov [con_handle],1
43 mov esi,_logo
44 call display_string
45
46 call get_params
47 jc information
48
49 call init_memory
50
51 mov esi,_memory_prefix
52 call display_string
53 mov eax,[memory_end]
54 sub eax,[memory_start]
55 add eax,[additional_memory_end]
56 sub eax,[additional_memory]
57 shr eax,10
58 call display_number
59 mov esi,_memory_suffix
60 call display_string
61
62 ccall gettimeofday,buffer,0
63 mov eax,dword [buffer]
64 mov ecx,1000
65 mul ecx
66 mov ebx,eax
67 mov eax,dword [buffer+4]
68 div ecx
69 add eax,ebx
70 mov [start_time],eax
71
72 and [preprocessing_done],0
73 call preprocessor
74 or [preprocessing_done],-1
75 call parser
76 call assembler
77 call formatter
78
79 call display_user_messages
80 movzx eax,[current_pass]
81 inc eax
82 call display_number
83 mov esi,_passes_suffix
84 call display_string
85 ccall gettimeofday,buffer,0
86 mov eax,dword [buffer]
87 mov ecx,1000
88 mul ecx
89 mov ebx,eax
90 mov eax,dword [buffer+4]
91 div ecx
92 add eax,ebx
93 sub eax,[start_time]
94 jnc time_ok
95 add eax,3600000
96 time_ok:
97 xor edx,edx
98 mov ebx,100
99 div ebx
100 or eax,eax
101 jz display_bytes_count
102 xor edx,edx
103 mov ebx,10
104 div ebx
105 push edx
106 call display_number
107 mov dl,'.'
108 call display_character
109 pop eax
110 call display_number
111 mov esi,_seconds_suffix
112 call display_string
113 display_bytes_count:
114 mov eax,[written_size]
115 call display_number
116 mov esi,_bytes_suffix
117 call display_string
118 xor al,al
119 jmp exit_program
120
121 information:
122 mov esi,_usage
123 call display_string
124 mov al,1
125 jmp exit_program
126
127 get_params:
128 mov [input_file],0
129 mov [output_file],0
130 mov [symbols_file],0
131 mov [memory_setting],0
132 mov [passes_limit],100
133
134 mov ecx,[argc]
135 mov ebx,[argv]
136 add ebx,4
137 dec ecx
138 jz bad_params
139 mov [definitions_pointer],predefinitions
140 get_param:
141 mov esi,[ebx]
142 mov al,[esi]
143 cmp al,'-'
144 je option_param
145 cmp [input_file],0
146 jne get_output_file
147 mov [input_file],esi
148 jmp next_param
149 get_output_file:
150 cmp [output_file],0
151 jne bad_params
152 mov [output_file],esi
153 jmp next_param
154 option_param:
155 inc esi
156 lodsb
157 cmp al,'m'
158 je memory_option
159 cmp al,'M'
160 je memory_option
161 cmp al,'p'
162 je passes_option
163 cmp al,'P'
164 je passes_option
165 cmp al,'d'
166 je definition_option
167 cmp al,'D'
168 je definition_option
169 cmp al,'s'
170 je symbols_option
171 cmp al,'S'
172 je symbols_option
173 bad_params:
174 stc
175 ret
176 memory_option:
177 cmp byte [esi],0
178 jne get_memory_setting
179 dec ecx
180 jz bad_params
181 add ebx,4
182 mov esi,[ebx]
183 get_memory_setting:
184 call get_option_value
185 or edx,edx
186 jz bad_params
187 cmp edx,1 shl (32-10)
188 jae bad_params
189 mov [memory_setting],edx
190 jmp next_param
191 passes_option:
192 cmp byte [esi],0
193 jne get_passes_setting
194 dec ecx
195 jz bad_params
196 add ebx,4
197 mov esi,[ebx]
198 get_passes_setting:
199 call get_option_value
200 or edx,edx
201 jz bad_params
202 cmp edx,10000h
203 ja bad_params
204 mov [passes_limit],dx
205 next_param:
206 add ebx,4
207 dec ecx
208 jnz get_param
209 cmp [input_file],0
210 je bad_params
211 mov eax,[definitions_pointer]
212 mov byte [eax],0
213 mov [initial_definitions],predefinitions
214 clc
215 ret
216 definition_option:
217 cmp byte [esi],0
218 jne get_definition
219 dec ecx
220 jz bad_params
221 add ebx,4
222 mov esi,[ebx]
223 get_definition:
224 push edi
225 mov edi,[definitions_pointer]
226 call convert_definition_option
227 mov [definitions_pointer],edi
228 pop edi
229 jc bad_params
230 jmp next_param
231 symbols_option:
232 cmp byte [esi],0
233 jne get_symbols_setting
234 dec ecx
235 jz bad_params
236 add ebx,4
237 mov esi,[ebx]
238 get_symbols_setting:
239 mov [symbols_file],esi
240 jmp next_param
241 get_option_value:
242 xor eax,eax
243 mov edx,eax
244 get_option_digit:
245 lodsb
246 cmp al,20h
247 je option_value_ok
248 cmp al,0Dh
249 je option_value_ok
250 or al,al
251 jz option_value_ok
252 sub al,30h
253 jc invalid_option_value
254 cmp al,9
255 ja invalid_option_value
256 imul edx,10
257 jo invalid_option_value
258 add edx,eax
259 jc invalid_option_value
260 jmp get_option_digit
261 option_value_ok:
262 dec esi
263 clc
264 ret
265 invalid_option_value:
266 stc
267 ret
268 convert_definition_option:
269 mov edx,edi
270 cmp edi,predefinitions+1000h
271 jae bad_definition_option
272 xor al,al
273 stosb
274 copy_definition_name:
275 lodsb
276 cmp al,'='
277 je copy_definition_value
278 cmp al,20h
279 je bad_definition_option
280 or al,al
281 jz bad_definition_option
282 cmp edi,predefinitions+1000h
283 jae bad_definition_option
284 stosb
285 inc byte [edx]
286 jnz copy_definition_name
287 bad_definition_option:
288 stc
289 ret
290 copy_definition_value:
291 lodsb
292 cmp al,20h
293 je definition_value_end
294 or al,al
295 jz definition_value_end
296 cmp edi,predefinitions+1000h
297 jae bad_definition_option
298 stosb
299 jmp copy_definition_value
300 definition_value_end:
301 dec esi
302 cmp edi,predefinitions+1000h
303 jae bad_definition_option
304 xor al,al
305 stosb
306 clc
307 ret
308
309 include 'system.inc'
310
311 include '..\version.inc'
312
313 _copyright db 'Copyright (c) 1999-2022, Tomasz Grysztar',0xA,0
314
315 _logo db 'flat assembler version ',VERSION_STRING,0
316 _usage db 0xA
317 db 'usage: fasm <source> [output]',0xA
318 db 'optional settings:',0xA
319 db ' -m <limit> set the limit in kilobytes for the available memory',0xA
320 db ' -p <limit> set the maximum allowed number of passes',0xA
321 db ' -d <name>=<value> define symbolic variable',0xA
322 db ' -s <file> dump symbolic information for debugging',0xA
323 db 0
324 _memory_prefix db ' (',0
325 _memory_suffix db ' kilobytes memory)',0xA,0
326 _passes_suffix db ' passes, ',0
327 _seconds_suffix db ' seconds, ',0
328 _bytes_suffix db ' bytes.',0xA,0
329
330 include '..\errors.inc'
331 include '..\symbdump.inc'
332 include '..\preproce.inc'
333 include '..\parser.inc'
334 include '..\exprpars.inc'
335 include '..\assemble.inc'
336 include '..\exprcalc.inc'
337 include '..\formats.inc'
338 include '..\x86_64.inc'
339 include '..\avx.inc'
340
341 include '..\tables.inc'
342 include '..\messages.inc'
343
344 section '.bss' writeable align 4
345
346 include '..\variable.inc'
347
348 argc dd ?
349 argv dd ?
350 stack_frame dd ?
351 memory_setting dd ?
352 definitions_pointer dd ?
353 start_time dd ?
354 timestamp dq ?
355 con_handle dd ?
356 displayed_count dd ?
357 last_displayed db ?
358 character db ?
359 preprocessing_done db ?
360
361 predefinitions rb 1000h
362 buffer rb 1000h