Merge tag 'upstream/1.71.39'
Upstream version 1.71.39
Tomasz Buchert
8 years ago
413 | 413 | priority value will be calculated first, you can of course change this |
414 | 414 | behavior by putting some parts of expression into parenthesis. The "+", "-", |
415 | 415 | "*" and "/" are standard arithmetical operations, "mod" calculates the |
416 | remainder from division. The "and", "or", "xor", "shl", "shr" and "not" | |
417 | perform the same logical operations as assembly instructions of those names. | |
418 | The "rva" and "plt" are special unary operators that perform conversions | |
419 | between different kinds of addresses, they can be used only with few of the | |
420 | output formats and their meaning may vary (see 2.4). | |
421 | The arithmetical and logical calculations are usually processed as if they | |
416 | remainder from division. The "and", "or", "xor", "shl", "shr", "bsf", "bsr" | |
417 | and "not" perform the same bit-logical operations as assembly instructions of | |
418 | those names. The "rva" and "plt" are special unary operators that perform | |
419 | conversions between different kinds of addresses, they can be used only with | |
420 | few of the output formats and their meaning may vary (see 2.4). | |
421 | The arithmetical and bit-logical calculations are processed as if they | |
422 | 422 | operated on infinite precision 2-adic numbers, and assembler signalizes an |
423 | 423 | overflow error if because of its limitations it is not table to perform the |
424 | 424 | required calculation, or if the result is too large number to fit in either |
425 | signed or unsigned range for the destination unit size. However "not", "xor" | |
426 | and "shr" operators are exceptions from this rule - if the value specified | |
427 | by numerical expression has to fit in a unit of specified size, and the | |
428 | arguments for operation fit into that size, the operation will be performed | |
429 | with precision limited to that size. | |
425 | signed or unsigned range for the destination unit size. | |
430 | 426 | The numbers in the expression are by default treated as a decimal, binary |
431 | 427 | numbers should have the "b" letter attached at the end, octal number should |
432 | 428 | end with "o" letter, hexadecimal numbers should begin with "0x" characters |
453 | 449 | characters. So "1.0", "1E0" and "1f" define the same floating point value, |
454 | 450 | while simple "1" defines an integer value. |
455 | 451 | |
456 | Table 1.4 Arithmetical and logical operators by priority | |
452 | Table 1.4 Arithmetical and bit-logical operators by priority | |
457 | 453 | /-------------------------\ |
458 | 454 | | Priority | Operators | |
459 | 455 | |==========|==============| |
469 | 465 | |----------|--------------| |
470 | 466 | | 5 | not | |
471 | 467 | |----------|--------------| |
472 | | 6 | rva plt | | |
468 | | 6 | bsf bsr | | |
469 | |----------|--------------| | |
470 | | 7 | rva plt | | |
473 | 471 | \-------------------------/ |
474 | 472 | |
475 | 473 | |
3944 | 3942 | some commas, such argument should be enclosed between "<" and ">" characters. |
3945 | 3943 | If it contains more than one "<" character, the same number of ">" should be |
3946 | 3944 | used to tell that the value of argument ends. |
3945 | When the name of the last argument of macroinstruction is followed by "&" | |
3946 | character, this argument consumes everything up to the end of line, including | |
3947 | commas. | |
3947 | 3948 | "purge" directive allows removing the last definition of specified |
3948 | 3949 | macroinstruction. It should be followed by one or more names of |
3949 | 3950 | macroinstructions, separated with commas. If such macroinstruction has not |
4641 | 4642 | followed by the minimum version of system that the executable is targeted to |
4642 | 4643 | (specified in form of floating-point value). Optional "DLL" and "WDM" keywords |
4643 | 4644 | mark the output file as a dynamic link library and WDM driver respectively, |
4644 | and the "large" keyword marks the executable as able to handle addresses | |
4645 | larger than 2 GB. | |
4645 | the "large" keyword marks the executable as able to handle addresses larger | |
4646 | than 2 GB and the "NX" keyword signalizes that the executable conforms to the | |
4647 | restriction of not executing code residing in non-executable sections. | |
4646 | 4648 | After those settings can follow the "at" operator and a numerical expression |
4647 | 4649 | specifying the base of PE image and then optionally "on" operator followed by |
4648 | 4650 | the quoted string containing file name selects custom MZ stub for PE program |
0 | 0 | |
1 | 1 | ; flat assembler interface for DOS |
2 | ; Copyright (c) 1999-2014, Tomasz Grysztar. | |
2 | ; Copyright (c) 1999-2015, Tomasz Grysztar. | |
3 | 3 | ; All rights reserved. |
4 | 4 | |
5 | 5 | format MZ |
113 | 113 | mov [symbols_file],0 |
114 | 114 | mov [memory_setting],0 |
115 | 115 | mov [passes_limit],100 |
116 | mov [definitions_pointer],predefinitions | |
116 | 117 | push ds |
117 | 118 | mov ds,[psp_segment] |
118 | 119 | mov esi,81h |
168 | 169 | je passes_option |
169 | 170 | cmp al,'P' |
170 | 171 | je passes_option |
172 | cmp al,'d' | |
173 | je definition_option | |
174 | cmp al,'D' | |
175 | je definition_option | |
171 | 176 | cmp al,'s' |
172 | 177 | je symbols_option |
173 | 178 | cmp al,'S' |
237 | 242 | ja invalid_option |
238 | 243 | mov [es:passes_limit],dx |
239 | 244 | jmp find_param |
245 | definition_option: | |
246 | lodsb | |
247 | cmp al,20h | |
248 | je definition_option | |
249 | cmp al,0Dh | |
250 | je bad_params | |
251 | or al,al | |
252 | jz bad_params | |
253 | dec esi | |
254 | push edi | |
255 | mov edi,[es:definitions_pointer] | |
256 | call convert_definition_option | |
257 | mov [es:definitions_pointer],edi | |
258 | pop edi | |
259 | jc invalid_option | |
260 | jmp find_param | |
240 | 261 | symbols_option: |
241 | 262 | mov [es:symbols_file],edi |
242 | 263 | find_symbols_file_name: |
256 | 277 | pop ds |
257 | 278 | cmp [input_file],0 |
258 | 279 | je no_input_file |
280 | mov eax,[definitions_pointer] | |
281 | mov byte [eax],0 | |
282 | mov [initial_definitions],predefinitions | |
259 | 283 | clc |
260 | 284 | ret |
261 | 285 | bad_params: |
263 | 287 | no_input_file: |
264 | 288 | stc |
265 | 289 | ret |
290 | convert_definition_option: | |
291 | mov ecx,edi | |
292 | xor al,al | |
293 | stosb | |
294 | copy_definition_name: | |
295 | lodsb | |
296 | cmp al,'=' | |
297 | je copy_definition_value | |
298 | cmp al,20h | |
299 | je bad_definition_option | |
300 | cmp al,0Dh | |
301 | je bad_definition_option | |
302 | or al,al | |
303 | jz bad_definition_option | |
304 | stosb | |
305 | inc byte [es:ecx] | |
306 | jnz copy_definition_name | |
307 | bad_definition_option: | |
308 | stc | |
309 | ret | |
310 | copy_definition_value: | |
311 | lodsb | |
312 | cmp al,20h | |
313 | je definition_value_end | |
314 | cmp al,0Dh | |
315 | je definition_value_end | |
316 | or al,al | |
317 | jz definition_value_end | |
318 | cmp al,'\' | |
319 | jne definition_value_character | |
320 | cmp byte [esi],20h | |
321 | jne definition_value_character | |
322 | lodsb | |
323 | definition_value_character: | |
324 | stosb | |
325 | jmp copy_definition_value | |
326 | definition_value_end: | |
327 | dec esi | |
328 | xor al,al | |
329 | stosb | |
330 | clc | |
331 | ret | |
266 | 332 | |
267 | 333 | include '..\version.inc' |
268 | 334 | |
269 | 335 | _logo db 'flat assembler version ',VERSION_STRING,24h |
270 | _copyright db 'Copyright (c) 1999-2014, Tomasz Grysztar',0Dh,0Ah,0 | |
336 | _copyright db 'Copyright (c) 1999-2015, Tomasz Grysztar',0Dh,0Ah,0 | |
271 | 337 | |
272 | 338 | _usage db 0Dh,0Ah |
273 | 339 | db 'usage: fasm <source> [output]',0Dh,0Ah |
274 | 340 | db 'optional settings:',0Dh,0Ah |
275 | db ' -m <limit> set the limit in kilobytes for the available memory',0Dh,0Ah | |
276 | db ' -p <limit> set the maximum allowed number of passes',0Dh,0Ah | |
277 | db ' -s <file> dump symbolic information for debugging',0Dh,0Ah | |
341 | db ' -m <limit> set the limit in kilobytes for the available memory',0Dh,0Ah | |
342 | db ' -p <limit> set the maximum allowed number of passes',0Dh,0Ah | |
343 | db ' -d <name>=<value> define symbolic variable',0Dh,0Ah | |
344 | db ' -s <file> dump symbolic information for debugging',0Dh,0Ah | |
278 | 345 | db 0 |
279 | 346 | _memory_prefix db ' (',0 |
280 | 347 | _memory_suffix db ' kilobytes memory)',0Dh,0Ah,0 |
345 | 412 | |
346 | 413 | memory_setting dd ? |
347 | 414 | start_time dd ? |
415 | definitions_pointer dd ? | |
348 | 416 | params rb 100h |
417 | predefinitions rb 100h | |
349 | 418 | |
350 | 419 | mode dw ? |
351 | 420 | real_mode_segment dw ? |
0 | 0 | |
1 | 1 | ; flat assembler interface for DOS |
2 | ; Copyright (c) 1999-2014, Tomasz Grysztar. | |
2 | ; Copyright (c) 1999-2015, Tomasz Grysztar. | |
3 | 3 | ; All rights reserved. |
4 | 4 | |
5 | 5 | segment modes use16 |
0 | 0 | |
1 | 1 | ; flat assembler interface for DOS |
2 | ; Copyright (c) 1999-2014, Tomasz Grysztar. | |
2 | ; Copyright (c) 1999-2015, Tomasz Grysztar. | |
3 | 3 | ; All rights reserved. |
4 | 4 | |
5 | 5 | go32: |
438 | 438 | jmp exit_program |
439 | 439 | assembler_error: |
440 | 440 | call display_user_messages |
441 | mov ebx,[current_line] | |
442 | test ebx,ebx | |
443 | jz display_error_message | |
441 | 444 | push dword 0 |
442 | mov ebx,[current_line] | |
443 | 445 | get_error_lines: |
444 | 446 | mov eax,[ebx] |
445 | 447 | cmp byte [eax],0 |
543 | 545 | pop ebx |
544 | 546 | or ebx,ebx |
545 | 547 | jnz display_error_line |
548 | display_error_message: | |
546 | 549 | mov esi,error_prefix |
547 | 550 | call display_string |
548 | 551 | pop esi |
0 | 0 | |
1 | 1 | ; flat assembler interface for Linux |
2 | ; Copyright (c) 1999-2014, Tomasz Grysztar. | |
2 | ; Copyright (c) 1999-2015, Tomasz Grysztar. | |
3 | 3 | ; All rights reserved. |
4 | 4 | |
5 | 5 | format ELF executable 3 |
114 | 114 | add ebx,8 |
115 | 115 | dec ecx |
116 | 116 | jz bad_params |
117 | mov [definitions_pointer],predefinitions | |
117 | 118 | get_param: |
118 | 119 | mov esi,[ebx] |
119 | 120 | mov al,[esi] |
139 | 140 | je passes_option |
140 | 141 | cmp al,'P' |
141 | 142 | je passes_option |
143 | cmp al,'d' | |
144 | je definition_option | |
145 | cmp al,'D' | |
146 | je definition_option | |
142 | 147 | cmp al,'s' |
143 | 148 | je symbols_option |
144 | 149 | cmp al,'S' |
181 | 186 | jnz get_param |
182 | 187 | cmp [input_file],0 |
183 | 188 | je bad_params |
189 | mov eax,[definitions_pointer] | |
190 | mov byte [eax],0 | |
191 | mov [initial_definitions],predefinitions | |
184 | 192 | clc |
185 | 193 | ret |
194 | definition_option: | |
195 | cmp byte [esi],0 | |
196 | jne get_definition | |
197 | dec ecx | |
198 | jz bad_params | |
199 | add ebx,4 | |
200 | mov esi,[ebx] | |
201 | get_definition: | |
202 | push edi | |
203 | mov edi,[definitions_pointer] | |
204 | call convert_definition_option | |
205 | mov [definitions_pointer],edi | |
206 | pop edi | |
207 | jc bad_params | |
208 | jmp next_param | |
186 | 209 | symbols_option: |
187 | 210 | cmp byte [esi],0 |
188 | 211 | jne get_symbols_setting |
218 | 241 | invalid_option_value: |
219 | 242 | stc |
220 | 243 | ret |
244 | convert_definition_option: | |
245 | mov edx,edi | |
246 | xor al,al | |
247 | stosb | |
248 | copy_definition_name: | |
249 | lodsb | |
250 | cmp al,'=' | |
251 | je copy_definition_value | |
252 | cmp al,20h | |
253 | je bad_definition_option | |
254 | or al,al | |
255 | jz bad_definition_option | |
256 | stosb | |
257 | inc byte [edx] | |
258 | jnz copy_definition_name | |
259 | bad_definition_option: | |
260 | stc | |
261 | ret | |
262 | copy_definition_value: | |
263 | lodsb | |
264 | cmp al,20h | |
265 | je definition_value_end | |
266 | or al,al | |
267 | jz definition_value_end | |
268 | stosb | |
269 | jmp copy_definition_value | |
270 | definition_value_end: | |
271 | dec esi | |
272 | xor al,al | |
273 | stosb | |
274 | clc | |
275 | ret | |
221 | 276 | |
222 | 277 | include 'system.inc' |
223 | 278 | |
224 | 279 | include '..\version.inc' |
225 | 280 | |
226 | _copyright db 'Copyright (c) 1999-2014, Tomasz Grysztar',0xA,0 | |
281 | _copyright db 'Copyright (c) 1999-2015, Tomasz Grysztar',0xA,0 | |
227 | 282 | |
228 | 283 | _logo db 'flat assembler version ',VERSION_STRING,0 |
229 | 284 | _usage db 0xA |
230 | 285 | db 'usage: fasm <source> [output]',0xA |
231 | 286 | db 'optional settings:',0xA |
232 | db ' -m <limit> set the limit in kilobytes for the available memory',0Dh,0Ah | |
233 | db ' -p <limit> set the maximum allowed number of passes',0Dh,0Ah | |
234 | db ' -s <file> dump symbolic information for debugging',0Dh,0Ah | |
287 | db ' -m <limit> set the limit in kilobytes for the available memory',0Dh,0Ah | |
288 | db ' -p <limit> set the maximum allowed number of passes',0Dh,0Ah | |
289 | db ' -d <name>=<value> define symbolic variable',0Dh,0Ah | |
290 | db ' -s <file> dump symbolic information for debugging',0Dh,0Ah | |
235 | 291 | db 0 |
236 | 292 | _memory_prefix db ' (',0 |
237 | 293 | _memory_suffix db ' kilobytes memory)',0xA,0 |
261 | 317 | |
262 | 318 | command_line dd ? |
263 | 319 | memory_setting dd ? |
320 | definitions_pointer dd ? | |
264 | 321 | environment dd ? |
265 | 322 | timestamp dq ? |
266 | 323 | start_time dd ? |
269 | 326 | last_displayed db ? |
270 | 327 | character db ? |
271 | 328 | |
329 | predefinitions rb 1000h | |
272 | 330 | buffer rb 1000h |
0 | 0 | |
1 | 1 | ; flat assembler interface for Linux |
2 | ; Copyright (c) 1999-2014, Tomasz Grysztar. | |
2 | ; Copyright (c) 1999-2015, Tomasz Grysztar. | |
3 | 3 | ; All rights reserved. |
4 | 4 | |
5 | 5 | O_ACCMODE = 0003o |
284 | 284 | assembler_error: |
285 | 285 | mov [con_handle],2 |
286 | 286 | call display_user_messages |
287 | mov ebx,[current_line] | |
288 | test ebx,ebx | |
289 | jz display_error_message | |
287 | 290 | push dword 0 |
288 | mov ebx,[current_line] | |
289 | 291 | get_error_lines: |
290 | 292 | mov eax,[ebx] |
291 | 293 | cmp byte [eax],0 |
377 | 379 | pop ebx |
378 | 380 | or ebx,ebx |
379 | 381 | jnz display_error_line |
382 | display_error_message: | |
380 | 383 | mov esi,error_prefix |
381 | 384 | call display_string |
382 | 385 | pop esi |
0 | 0 | |
1 | 1 | ; flat assembler interface for Win32 |
2 | ; Copyright (c) 1999-2014, Tomasz Grysztar. | |
2 | ; Copyright (c) 1999-2015, Tomasz Grysztar. | |
3 | 3 | ; All rights reserved. |
4 | 4 | |
5 | 5 | format PE console |
81 | 81 | mov [memory_setting],0 |
82 | 82 | mov [passes_limit],100 |
83 | 83 | call [GetCommandLine] |
84 | mov [definitions_pointer],predefinitions | |
84 | 85 | mov esi,eax |
85 | 86 | mov edi,params |
86 | 87 | find_command_start: |
154 | 155 | je passes_option |
155 | 156 | cmp al,'P' |
156 | 157 | je passes_option |
158 | cmp al,'d' | |
159 | je definition_option | |
160 | cmp al,'D' | |
161 | je definition_option | |
157 | 162 | cmp al,'s' |
158 | 163 | je symbols_option |
159 | 164 | cmp al,'S' |
220 | 225 | ja bad_params |
221 | 226 | mov [passes_limit],dx |
222 | 227 | jmp find_param |
228 | definition_option: | |
229 | lodsb | |
230 | cmp al,20h | |
231 | je definition_option | |
232 | cmp al,0Dh | |
233 | je bad_params | |
234 | or al,al | |
235 | jz bad_params | |
236 | dec esi | |
237 | push edi | |
238 | mov edi,[definitions_pointer] | |
239 | call convert_definition_option | |
240 | mov [definitions_pointer],edi | |
241 | pop edi | |
242 | jc bad_params | |
243 | jmp find_param | |
223 | 244 | symbols_option: |
224 | 245 | mov [symbols_file],edi |
225 | 246 | find_symbols_file_name: |
236 | 257 | all_params: |
237 | 258 | cmp [input_file],0 |
238 | 259 | je bad_params |
260 | mov eax,[definitions_pointer] | |
261 | mov byte [eax],0 | |
262 | mov [initial_definitions],predefinitions | |
263 | clc | |
264 | ret | |
265 | convert_definition_option: | |
266 | mov ecx,edi | |
267 | xor al,al | |
268 | stosb | |
269 | copy_definition_name: | |
270 | lodsb | |
271 | cmp al,'=' | |
272 | je copy_definition_value | |
273 | cmp al,20h | |
274 | je bad_definition_option | |
275 | cmp al,0Dh | |
276 | je bad_definition_option | |
277 | or al,al | |
278 | jz bad_definition_option | |
279 | stosb | |
280 | inc byte [ecx] | |
281 | jnz copy_definition_name | |
282 | bad_definition_option: | |
283 | stc | |
284 | ret | |
285 | copy_definition_value: | |
286 | lodsb | |
287 | cmp al,20h | |
288 | je definition_value_end | |
289 | cmp al,0Dh | |
290 | je definition_value_end | |
291 | or al,al | |
292 | jz definition_value_end | |
293 | cmp al,'\' | |
294 | jne definition_value_character | |
295 | cmp byte [esi],20h | |
296 | jne definition_value_character | |
297 | lodsb | |
298 | definition_value_character: | |
299 | stosb | |
300 | jmp copy_definition_value | |
301 | definition_value_end: | |
302 | dec esi | |
303 | xor al,al | |
304 | stosb | |
239 | 305 | clc |
240 | 306 | ret |
241 | 307 | |
259 | 325 | |
260 | 326 | include '..\version.inc' |
261 | 327 | |
262 | _copyright db 'Copyright (c) 1999-2014, Tomasz Grysztar',0Dh,0Ah,0 | |
328 | _copyright db 'Copyright (c) 1999-2015, Tomasz Grysztar',0Dh,0Ah,0 | |
263 | 329 | |
264 | 330 | _logo db 'flat assembler version ',VERSION_STRING,0 |
265 | 331 | _usage db 0Dh,0Ah |
266 | 332 | db 'usage: fasm <source> [output]',0Dh,0Ah |
267 | 333 | db 'optional settings:',0Dh,0Ah |
268 | db ' -m <limit> set the limit in kilobytes for the available memory',0Dh,0Ah | |
269 | db ' -p <limit> set the maximum allowed number of passes',0Dh,0Ah | |
270 | db ' -s <file> dump symbolic information for debugging',0Dh,0Ah | |
334 | db ' -m <limit> set the limit in kilobytes for the available memory',0Dh,0Ah | |
335 | db ' -p <limit> set the maximum allowed number of passes',0Dh,0Ah | |
336 | db ' -d <name>=<value> define symbolic variable',0Dh,0Ah | |
337 | db ' -s <file> dump symbolic information for debugging',0Dh,0Ah | |
271 | 338 | db 0 |
272 | 339 | _memory_prefix db ' (',0 |
273 | 340 | _memory_suffix db ' kilobytes memory)',0Dh,0Ah,0 |
282 | 349 | con_handle dd ? |
283 | 350 | memory_setting dd ? |
284 | 351 | start_time dd ? |
352 | definitions_pointer dd ? | |
285 | 353 | bytes_count dd ? |
286 | 354 | displayed_count dd ? |
287 | 355 | character db ? |
289 | 357 | |
290 | 358 | params rb 1000h |
291 | 359 | options rb 1000h |
360 | predefinitions rb 1000h | |
292 | 361 | buffer rb 4000h |
293 | 362 | |
294 | 363 | stack 10000h |
0 | 0 | |
1 | 1 | ; flat assembler interface for Win32 |
2 | ; Copyright (c) 1999-2014, Tomasz Grysztar. | |
2 | ; Copyright (c) 1999-2015, Tomasz Grysztar. | |
3 | 3 | ; All rights reserved. |
4 | 4 | |
5 | 5 | CREATE_NEW = 1 |
314 | 314 | assembler_error: |
315 | 315 | mov [con_handle],STD_ERROR_HANDLE |
316 | 316 | call display_user_messages |
317 | mov ebx,[current_line] | |
318 | test ebx,ebx | |
319 | jz display_error_message | |
317 | 320 | push dword 0 |
318 | mov ebx,[current_line] | |
319 | 321 | get_error_lines: |
320 | 322 | mov eax,[ebx] |
321 | 323 | cmp byte [eax],0 |
407 | 409 | pop ebx |
408 | 410 | or ebx,ebx |
409 | 411 | jnz display_error_line |
412 | display_error_message: | |
410 | 413 | mov esi,error_prefix |
411 | 414 | call display_string |
412 | 415 | pop esi |
0 | 0 | |
1 | 1 | ; flat assembler core |
2 | ; Copyright (c) 1999-2014, Tomasz Grysztar. | |
2 | ; Copyright (c) 1999-2015, Tomasz Grysztar. | |
3 | 3 | ; All rights reserved. |
4 | 4 | |
5 | 5 | assembler: |
328 | 328 | cmp eax,0Fh |
329 | 329 | jb invalid_use_of_symbol |
330 | 330 | je reserved_word_used_as_symbol |
331 | mov edx,[eax+8] | |
332 | push edx | |
333 | cmp [current_pass],0 | |
334 | je get_constant_value | |
335 | test dl,4 | |
336 | jnz get_constant_value | |
337 | mov cx,[current_pass] | |
338 | cmp cx,[eax+16] | |
339 | je get_constant_value | |
340 | or dl,4 | |
341 | mov [eax+8],dl | |
342 | get_constant_value: | |
343 | push eax | |
344 | mov al,byte [esi-1] | |
345 | 331 | push eax |
346 | 332 | or [size_override],-1 |
347 | 333 | call get_value |
348 | 334 | pop ebx |
349 | mov ch,bl | |
350 | pop ebx | |
351 | pop ecx | |
352 | test cl,4 | |
353 | jnz constant_referencing_mode_ok | |
354 | and byte [ebx+8],not 4 | |
355 | constant_referencing_mode_ok: | |
356 | 335 | xor cl,cl |
357 | 336 | mov ch,[value_type] |
358 | 337 | cmp ch,3 |
452 | 431 | or byte [ebx+0Ah],2 |
453 | 432 | jmp continue_line |
454 | 433 | assemble_instruction: |
455 | ; mov [operand_size],0 | |
456 | ; mov [size_override],0 | |
457 | ; mov [operand_prefix],0 | |
458 | ; mov [opcode_prefix],0 | |
434 | ; mov [operand_size],0 | |
435 | ; mov [size_override],0 | |
436 | ; mov [operand_prefix],0 | |
437 | ; mov [opcode_prefix],0 | |
459 | 438 | and dword [operand_size],0 |
460 | ; mov [rex_prefix],0 | |
461 | ; mov [vex_required],0 | |
462 | ; mov [vex_register],0 | |
463 | ; mov [immediate_size],0 | |
439 | ; mov [rex_prefix],0 | |
440 | ; mov [vex_required],0 | |
441 | ; mov [vex_register],0 | |
442 | ; mov [immediate_size],0 | |
464 | 443 | and dword [rex_prefix],0 |
465 | 444 | call instruction_handler |
466 | 445 | instruction_handler: |
0 | 0 | |
1 | 1 | ; flat assembler core |
2 | ; Copyright (c) 1999-2014, Tomasz Grysztar. | |
2 | ; Copyright (c) 1999-2015, Tomasz Grysztar. | |
3 | 3 | ; All rights reserved. |
4 | 4 | |
5 | 5 | avx_single_source_pd_instruction: |
0 | 0 | |
1 | 1 | ; flat assembler core |
2 | ; Copyright (c) 1999-2014, Tomasz Grysztar. | |
2 | ; Copyright (c) 1999-2015, Tomasz Grysztar. | |
3 | 3 | ; All rights reserved. |
4 | 4 | |
5 | 5 | out_of_memory: |
23 | 23 | jmp general_error |
24 | 24 | format_limitations_exceeded: |
25 | 25 | push _format_limitations_exceeded |
26 | jmp general_error | |
27 | invalid_definition: | |
28 | push _invalid_definition | |
26 | 29 | general_error: |
27 | 30 | cmp [symbols_file],0 |
28 | 31 | je fatal_error |
0 | 0 | |
1 | 1 | ; flat assembler core |
2 | ; Copyright (c) 1999-2014, Tomasz Grysztar. | |
2 | ; Copyright (c) 1999-2015, Tomasz Grysztar. | |
3 | 3 | ; All rights reserved. |
4 | 4 | |
5 | 5 | calculate_expression: |
10 | 10 | cmp byte [esi],'.' |
11 | 11 | je convert_fp |
12 | 12 | calculation_loop: |
13 | mov eax,[tagged_blocks] | |
14 | sub eax,0Ch | |
15 | cmp eax,edi | |
16 | jbe out_of_memory | |
13 | 17 | lods byte [esi] |
14 | 18 | cmp al,1 |
15 | 19 | je get_byte_number |
34 | 38 | sub edi,14h |
35 | 39 | mov ebx,edi |
36 | 40 | sub ebx,14h |
37 | cmp al,0E0h | |
41 | cmp al,0F0h | |
38 | 42 | je calculate_rva |
39 | cmp al,0E1h | |
43 | cmp al,0F1h | |
40 | 44 | je calculate_plt |
41 | 45 | cmp al,0D0h |
42 | 46 | je calculate_not |
47 | cmp al,0E0h | |
48 | je calculate_bsf | |
49 | cmp al,0E1h | |
50 | je calculate_bsr | |
43 | 51 | cmp al,083h |
44 | 52 | je calculate_neg |
45 | 53 | mov dx,[ebx+8] |
621 | 629 | xor [ebx],eax |
622 | 630 | xor [ebx+4],edx |
623 | 631 | xor [ebx+13],cl |
624 | jz calculation_loop | |
625 | or cl,cl | |
626 | jz xor_size_check | |
627 | xor eax,[ebx] | |
628 | xor edx,[ebx+4] | |
629 | xor_size_check: | |
630 | mov cl,[value_size] | |
631 | cmp cl,1 | |
632 | je xor_byte_result | |
633 | cmp cl,2 | |
634 | je xor_word_result | |
635 | cmp cl,4 | |
636 | je xor_dword_result | |
637 | cmp cl,6 | |
638 | je xor_pword_result | |
639 | cmp cl,8 | |
640 | jne calculation_loop | |
641 | xor edx,[ebx+4] | |
642 | js xor_result_truncated | |
643 | jmp calculation_loop | |
644 | xor_pword_result: | |
645 | test edx,0FFFF0000h | |
646 | jnz calculation_loop | |
647 | cmp word [ebx+6],-1 | |
648 | jne calculation_loop | |
649 | xor dx,[ebx+4] | |
650 | jns calculation_loop | |
651 | not word [ebx+6] | |
652 | jmp xor_result_truncated | |
653 | xor_dword_result: | |
654 | test edx,edx | |
655 | jnz calculation_loop | |
656 | cmp dword [ebx+4],-1 | |
657 | jne calculation_loop | |
658 | xor eax,[ebx] | |
659 | jns calculation_loop | |
660 | not dword [ebx+4] | |
661 | jmp xor_result_truncated | |
662 | xor_word_result: | |
663 | test edx,edx | |
664 | jnz calculation_loop | |
665 | test eax,0FFFF0000h | |
666 | jnz calculation_loop | |
667 | cmp dword [ebx+4],-1 | |
668 | jne calculation_loop | |
669 | cmp word [ebx+2],-1 | |
670 | jne calculation_loop | |
671 | xor ax,[ebx] | |
672 | jns calculation_loop | |
673 | not dword [ebx+4] | |
674 | not word [ebx+2] | |
675 | jmp xor_result_truncated | |
676 | xor_byte_result: | |
677 | test edx,edx | |
678 | jnz calculation_loop | |
679 | test eax,0FFFFFF00h | |
680 | jnz calculation_loop | |
681 | cmp dword [ebx+4],-1 | |
682 | jne calculation_loop | |
683 | cmp word [ebx+2],-1 | |
684 | jne calculation_loop | |
685 | cmp byte [ebx+1],-1 | |
686 | jne calculation_loop | |
687 | xor al,[ebx] | |
688 | jns calculation_loop | |
689 | not dword [ebx+4] | |
690 | not word [ebx+2] | |
691 | not byte [ebx+1] | |
692 | xor_result_truncated: | |
693 | mov byte [ebx+13],0 | |
694 | 632 | jmp calculation_loop |
695 | 633 | shr_negative: |
696 | 634 | mov byte [edi+13],0 |
759 | 697 | calculate_shr: |
760 | 698 | cmp byte [edi+13],0 |
761 | 699 | jne shr_negative |
762 | cmp byte [ebx+13],0 | |
763 | je do_shr | |
764 | mov al,[value_size] | |
765 | cmp al,1 | |
766 | je shr_negative_byte | |
767 | cmp al,2 | |
768 | je shr_negative_word | |
769 | cmp al,4 | |
770 | je shr_negative_dword | |
771 | cmp al,6 | |
772 | je shr_negative_pword | |
773 | cmp al,8 | |
774 | jne do_shr | |
775 | shr_negative_qword: | |
776 | test byte [ebx+7],80h | |
777 | jz do_shr | |
778 | shr_truncated: | |
779 | mov byte [ebx+13],0 | |
780 | do_shr: | |
781 | 700 | mov edx,[ebx+4] |
782 | 701 | mov eax,[ebx] |
783 | 702 | cmp dword [edi+4],0 |
807 | 726 | mov dword [ebx],eax |
808 | 727 | mov dword [ebx+4],eax |
809 | 728 | jmp calculation_loop |
810 | shr_negative_byte: | |
811 | cmp dword [ebx+4],-1 | |
812 | jne do_shr | |
813 | cmp word [ebx+2],-1 | |
814 | jne do_shr | |
815 | cmp byte [ebx+1],-1 | |
816 | jne do_shr | |
817 | test byte [ebx],80h | |
818 | jz do_shr | |
819 | not dword [ebx+4] | |
820 | not word [ebx+2] | |
821 | not byte [ebx+1] | |
822 | jmp shr_truncated | |
823 | shr_negative_word: | |
824 | cmp dword [ebx+4],-1 | |
825 | jne do_shr | |
826 | cmp word [ebx+2],-1 | |
827 | jne do_shr | |
828 | test byte [ebx+1],80h | |
829 | jz do_shr | |
830 | not dword [ebx+4] | |
831 | not word [ebx+2] | |
832 | jmp shr_truncated | |
833 | shr_negative_dword: | |
834 | cmp dword [ebx+4],-1 | |
835 | jne do_shr | |
836 | test byte [ebx+3],80h | |
837 | jz do_shr | |
838 | not dword [ebx+4] | |
839 | jmp shr_truncated | |
840 | shr_negative_pword: | |
841 | cmp word [ebx+6],-1 | |
842 | jne do_shr | |
843 | test byte [ebx+5],80h | |
844 | jz do_shr | |
845 | not word [ebx+6] | |
846 | jmp shr_truncated | |
847 | 729 | calculate_not: |
848 | 730 | cmp word [edi+8],0 |
849 | 731 | jne invalid_expression |
851 | 733 | je not_ok |
852 | 734 | call recoverable_misuse |
853 | 735 | not_ok: |
854 | mov al,[value_size] | |
855 | cmp al,1 | |
856 | je not_byte | |
857 | cmp al,2 | |
858 | je not_word | |
859 | cmp al,4 | |
860 | je not_dword | |
861 | cmp al,6 | |
862 | je not_pword | |
863 | cmp al,8 | |
864 | je not_qword | |
865 | 736 | not dword [edi] |
866 | 737 | not dword [edi+4] |
867 | 738 | not byte [edi+13] |
868 | 739 | add edi,14h |
869 | 740 | jmp calculation_loop |
870 | not_qword: | |
871 | not dword [edi] | |
872 | not dword [edi+4] | |
873 | finish_not: | |
874 | mov byte [edi+13],0 | |
741 | calculate_bsf: | |
742 | cmp word [edi+8],0 | |
743 | jne invalid_expression | |
744 | cmp byte [edi+12],0 | |
745 | je bsf_ok | |
746 | call recoverable_misuse | |
747 | bsf_ok: | |
748 | xor ecx,ecx | |
749 | bsf eax,[edi] | |
750 | jnz finish_bs | |
751 | mov ecx,32 | |
752 | bsf eax,[edi+4] | |
753 | jnz finish_bs | |
754 | cmp byte [edi+13],0 | |
755 | jne finish_bs | |
756 | bs_overflow: | |
757 | call recoverable_overflow | |
875 | 758 | add edi,14h |
876 | 759 | jmp calculation_loop |
877 | not_byte: | |
878 | cmp dword [edi+4],0 | |
879 | jne not_qword | |
880 | cmp word [edi+2],0 | |
881 | jne not_qword | |
882 | cmp byte [edi+1],0 | |
883 | jne not_qword | |
884 | not byte [edi] | |
885 | jmp finish_not | |
886 | not_word: | |
887 | cmp dword [edi+4],0 | |
888 | jne not_qword | |
889 | cmp word [edi+2],0 | |
890 | jne not_qword | |
891 | not word [edi] | |
892 | jmp finish_not | |
893 | not_dword: | |
894 | cmp dword [edi+4],0 | |
895 | jne not_qword | |
896 | not dword [edi] | |
897 | jmp finish_not | |
898 | not_pword: | |
899 | cmp word [edi+6],0 | |
900 | jne not_qword | |
901 | not word [edi+4] | |
902 | not dword [edi] | |
903 | jmp finish_not | |
760 | calculate_bsr: | |
761 | cmp word [edi+8],0 | |
762 | jne invalid_expression | |
763 | cmp byte [edi+12],0 | |
764 | je bsr_ok | |
765 | call recoverable_misuse | |
766 | bsr_ok: | |
767 | cmp byte [edi+13],0 | |
768 | jne bs_overflow | |
769 | mov ecx,32 | |
770 | bsr eax,[edi+4] | |
771 | jnz finish_bs | |
772 | xor ecx,ecx | |
773 | bsr eax,[edi] | |
774 | jz bs_overflow | |
775 | finish_bs: | |
776 | add eax,ecx | |
777 | xor edx,edx | |
778 | mov [edi],eax | |
779 | mov [edi+4],edx | |
780 | mov [edi+13],dl | |
781 | add edi,14h | |
782 | jmp calculation_loop | |
904 | 783 | calculate_neg: |
905 | 784 | cmp byte [edi+8],0 |
906 | 785 | je neg_first_register_ok |
1348 | 1227 | je byte_positive |
1349 | 1228 | cmp edx,-1 |
1350 | 1229 | jne range_exceeded |
1351 | cmp eax,-80h | |
1230 | cmp eax,-100h | |
1352 | 1231 | jb range_exceeded |
1353 | 1232 | ret |
1354 | 1233 | byte_positive: |
1392 | 1271 | je word_positive |
1393 | 1272 | cmp edx,-1 |
1394 | 1273 | jne range_exceeded |
1395 | cmp eax,-8000h | |
1274 | cmp eax,-10000h | |
1396 | 1275 | jb range_exceeded |
1397 | 1276 | ret |
1398 | 1277 | word_positive: |
1424 | 1303 | je dword_positive |
1425 | 1304 | cmp edx,-1 |
1426 | 1305 | jne range_exceeded |
1427 | bt eax,31 | |
1428 | jnc range_exceeded | |
1429 | 1306 | ret |
1430 | 1307 | dword_positive: |
1431 | 1308 | test edx,edx |
1443 | 1320 | mov edx,[edi+4] |
1444 | 1321 | cmp byte [edi+13],0 |
1445 | 1322 | je pword_positive |
1446 | cmp edx,-8000h | |
1323 | cmp edx,-10000h | |
1447 | 1324 | jb range_exceeded |
1448 | 1325 | ret |
1449 | 1326 | pword_positive: |
1457 | 1334 | check_qword_value: |
1458 | 1335 | mov eax,[edi] |
1459 | 1336 | mov edx,[edi+4] |
1460 | cmp byte [edi+13],0 | |
1461 | je qword_positive | |
1462 | cmp edx,-80000000h | |
1463 | jb range_exceeded | |
1464 | qword_positive: | |
1465 | 1337 | ret |
1466 | 1338 | get_count_value: |
1467 | 1339 | mov [value_size],8 |
1682 | 1554 | cmp bh,0F4h |
1683 | 1555 | jne invalid_address |
1684 | 1556 | cmp [free_address_range],0 |
1685 | jne check_qword_value | |
1686 | jmp check_dword_value | |
1557 | je check_dword_value | |
1558 | mov eax,[edi] | |
1559 | mov edx,[edi+4] | |
1560 | ret | |
1687 | 1561 | check_rip_relative_address: |
1688 | 1562 | mov eax,[edi] |
1689 | 1563 | cdq |
0 | 0 | |
1 | 1 | ; flat assembler core |
2 | ; Copyright (c) 1999-2014, Tomasz Grysztar. | |
2 | ; Copyright (c) 1999-2015, Tomasz Grysztar. | |
3 | 3 | ; All rights reserved. |
4 | 4 | |
5 | 5 | convert_expression: |
76 | 76 | ret |
77 | 77 | |
78 | 78 | convert_number: |
79 | lea eax,[edi-10h] | |
79 | lea eax,[edi+20h] | |
80 | 80 | mov edx,[memory_end] |
81 | 81 | cmp [source_start],0 |
82 | 82 | je check_memory_for_number |
128 | 128 | pop [current_offset] |
129 | 129 | lods byte [esi] |
130 | 130 | cmp al,')' |
131 | jne invalid_expression | |
131 | je subexpression_closed | |
132 | dec esi | |
133 | mov al,'!' | |
134 | stosb | |
135 | subexpression_closed: | |
132 | 136 | ret |
133 | 137 | symbol_value: |
134 | 138 | cmp [source_start],0 |
0 | 0 | |
1 | 1 | ; flat assembler core |
2 | ; Copyright (c) 1999-2014, Tomasz Grysztar. | |
2 | ; Copyright (c) 1999-2015, Tomasz Grysztar. | |
3 | 3 | ; All rights reserved. |
4 | 4 | |
5 | 5 | formatter: |
3493 | 3493 | shr eax,8 |
3494 | 3494 | stos dword [edi] |
3495 | 3495 | xor eax,eax |
3496 | stos dword [edi] | |
3497 | stos dword [edi] | |
3496 | push edx | |
3497 | mov edx,[esi+4] | |
3498 | add edx,[image_base] | |
3499 | xchg eax,[edx] | |
3500 | stos dword [edi] | |
3501 | cmp byte [esi],1 | |
3502 | je addend_64bit | |
3503 | pop edx | |
3504 | sar eax,31 | |
3505 | stos dword [edi] | |
3506 | jmp relocation_entry_ok | |
3507 | addend_64bit: | |
3508 | xor eax,eax | |
3509 | xchg eax,[edx+4] | |
3510 | stos dword [edi] | |
3511 | pop edx | |
3498 | 3512 | relocation_entry_ok: |
3499 | 3513 | add esi,0Ch |
3500 | 3514 | jmp convert_relocations |
0 | 0 | |
1 | 1 | ; flat assembler interface for Unix/libc |
2 | ; Copyright (c) 1999-2014, Tomasz Grysztar. | |
2 | ; Copyright (c) 1999-2015, Tomasz Grysztar. | |
3 | 3 | ; All rights reserved. |
4 | 4 | |
5 | 5 | format ELF |
127 | 127 | mov [symbols_file],0 |
128 | 128 | mov [memory_setting],0 |
129 | 129 | mov [passes_limit],100 |
130 | ||
131 | ||
130 | 132 | mov ecx,[argc] |
131 | 133 | mov ebx,[argv] |
132 | 134 | add ebx,4 |
133 | 135 | dec ecx |
134 | 136 | jz bad_params |
137 | mov [definitions_pointer],predefinitions | |
135 | 138 | get_param: |
136 | 139 | mov esi,[ebx] |
137 | 140 | mov al,[esi] |
157 | 160 | je passes_option |
158 | 161 | cmp al,'P' |
159 | 162 | je passes_option |
163 | cmp al,'d' | |
164 | je definition_option | |
165 | cmp al,'D' | |
166 | je definition_option | |
160 | 167 | cmp al,'s' |
161 | 168 | je symbols_option |
162 | 169 | cmp al,'S' |
199 | 206 | jnz get_param |
200 | 207 | cmp [input_file],0 |
201 | 208 | je bad_params |
209 | mov eax,[definitions_pointer] | |
210 | mov byte [eax],0 | |
211 | mov [initial_definitions],predefinitions | |
202 | 212 | clc |
203 | 213 | ret |
214 | definition_option: | |
215 | cmp byte [esi],0 | |
216 | jne get_definition | |
217 | dec ecx | |
218 | jz bad_params | |
219 | add ebx,4 | |
220 | mov esi,[ebx] | |
221 | get_definition: | |
222 | push edi | |
223 | mov edi,[definitions_pointer] | |
224 | call convert_definition_option | |
225 | mov [definitions_pointer],edi | |
226 | pop edi | |
227 | jc bad_params | |
228 | jmp next_param | |
204 | 229 | symbols_option: |
205 | 230 | cmp byte [esi],0 |
206 | 231 | jne get_symbols_setting |
238 | 263 | invalid_option_value: |
239 | 264 | stc |
240 | 265 | ret |
266 | convert_definition_option: | |
267 | mov edx,edi | |
268 | xor al,al | |
269 | stosb | |
270 | copy_definition_name: | |
271 | lodsb | |
272 | cmp al,'=' | |
273 | je copy_definition_value | |
274 | cmp al,20h | |
275 | je bad_definition_option | |
276 | or al,al | |
277 | jz bad_definition_option | |
278 | stosb | |
279 | inc byte [edx] | |
280 | jnz copy_definition_name | |
281 | bad_definition_option: | |
282 | stc | |
283 | ret | |
284 | copy_definition_value: | |
285 | lodsb | |
286 | cmp al,20h | |
287 | je definition_value_end | |
288 | or al,al | |
289 | jz definition_value_end | |
290 | stosb | |
291 | jmp copy_definition_value | |
292 | definition_value_end: | |
293 | dec esi | |
294 | xor al,al | |
295 | stosb | |
296 | clc | |
297 | ret | |
241 | 298 | |
242 | 299 | include 'system.inc' |
243 | 300 | |
244 | 301 | include '..\version.inc' |
245 | 302 | |
246 | _copyright db 'Copyright (c) 1999-2014, Tomasz Grysztar',0xA,0 | |
303 | _copyright db 'Copyright (c) 1999-2015, Tomasz Grysztar',0xA,0 | |
247 | 304 | |
248 | 305 | _logo db 'flat assembler version ',VERSION_STRING,0 |
249 | 306 | _usage db 0xA |
250 | 307 | db 'usage: fasm <source> [output]',0xA |
251 | 308 | db 'optional settings:',0xA |
252 | db ' -m <limit> set the limit in kilobytes for the available memory',0Dh,0Ah | |
253 | db ' -p <limit> set the maximum allowed number of passes',0Dh,0Ah | |
254 | db ' -s <file> dump symbolic information for debugging',0Dh,0Ah | |
309 | db ' -m <limit> set the limit in kilobytes for the available memory',0Dh,0Ah | |
310 | db ' -p <limit> set the maximum allowed number of passes',0Dh,0Ah | |
311 | db ' -d <name>=<value> define symbolic variable',0Dh,0Ah | |
312 | db ' -s <file> dump symbolic information for debugging',0Dh,0Ah | |
255 | 313 | db 0 |
256 | 314 | _memory_prefix db ' (',0 |
257 | 315 | _memory_suffix db ' kilobytes memory)',0xA,0 |
281 | 339 | argv dd ? |
282 | 340 | stack_frame dd ? |
283 | 341 | memory_setting dd ? |
342 | definitions_pointer dd ? | |
284 | 343 | start_time dd ? |
285 | 344 | timestamp dq ? |
286 | 345 | con_handle dd ? |
288 | 347 | last_displayed db ? |
289 | 348 | character db ? |
290 | 349 | |
350 | predefinitions rb 1000h | |
291 | 351 | buffer rb 1000h |
0 | 0 | |
1 | 1 | ; flat assembler interface for Unix/libc |
2 | ; Copyright (c) 1999-2014, Tomasz Grysztar. | |
2 | ; Copyright (c) 1999-2015, Tomasz Grysztar. | |
3 | 3 | ; All rights reserved. |
4 | 4 | |
5 | 5 | extrn malloc |
220 | 220 | assembler_error: |
221 | 221 | mov [con_handle],2 |
222 | 222 | call display_user_messages |
223 | mov ebx,[current_line] | |
224 | test ebx,ebx | |
225 | jz display_error_message | |
223 | 226 | push dword 0 |
224 | mov ebx,[current_line] | |
225 | 227 | get_error_lines: |
226 | 228 | mov eax,[ebx] |
227 | 229 | cmp byte [eax],0 |
313 | 315 | pop ebx |
314 | 316 | or ebx,ebx |
315 | 317 | jnz display_error_line |
318 | display_error_message: | |
316 | 319 | mov esi,error_prefix |
317 | 320 | call display_string |
318 | 321 | pop esi |
0 | 0 | |
1 | 1 | ; flat assembler core |
2 | ; Copyright (c) 1999-2014, Tomasz Grysztar. | |
2 | ; Copyright (c) 1999-2015, Tomasz Grysztar. | |
3 | 3 | ; All rights reserved. |
4 | 4 | |
5 | 5 | _out_of_memory db 'out of memory',0 |
0 | 0 | |
1 | 1 | ; flat assembler core |
2 | ; Copyright (c) 1999-2014, Tomasz Grysztar. | |
2 | ; Copyright (c) 1999-2015, Tomasz Grysztar. | |
3 | 3 | ; All rights reserved. |
4 | 4 | |
5 | 5 | parser: |
1257 | 1257 | inc esi |
1258 | 1258 | cmp byte [esi-1],'$' |
1259 | 1259 | je get_org_origin_id |
1260 | sub esi,ecx | |
1260 | sub esi,2 | |
1261 | 1261 | jmp find_label |
1262 | 1262 | get_current_offset_id: |
1263 | 1263 | xor eax,eax |
1362 | 1362 | cmp al,30h |
1363 | 1363 | jb name_first_char_ok |
1364 | 1364 | cmp al,39h |
1365 | jbe invalid_name | |
1365 | jbe numeric_name | |
1366 | 1366 | name_first_char_ok: |
1367 | 1367 | cmp al,'$' |
1368 | 1368 | jne check_for_reserved_word |
1369 | cmp ecx,1 | |
1370 | jne invalid_name | |
1369 | numeric_name: | |
1370 | add esi,ecx | |
1371 | 1371 | reserved_word: |
1372 | 1372 | mov eax,0Fh |
1373 | 1373 | pop edi |
0 | 0 | |
1 | 1 | ; flat assembler core |
2 | ; Copyright (c) 1999-2014, Tomasz Grysztar. | |
2 | ; Copyright (c) 1999-2015, Tomasz Grysztar. | |
3 | 3 | ; All rights reserved. |
4 | 4 | |
5 | 5 | preprocessor: |
41 | 41 | mov [hash_tree],eax |
42 | 42 | mov [error],eax |
43 | 43 | mov [macro_status],al |
44 | mov [current_line],eax | |
45 | mov esi,[initial_definitions] | |
46 | test esi,esi | |
47 | jz predefinitions_ok | |
48 | process_predefinitions: | |
49 | movzx ecx,byte [esi] | |
50 | test ecx,ecx | |
51 | jz predefinitions_ok | |
52 | inc esi | |
53 | lea eax,[esi+ecx] | |
54 | push eax | |
55 | mov ch,10b | |
56 | call add_preprocessor_symbol | |
57 | pop esi | |
58 | mov edi,[memory_start] | |
59 | mov [edx+8],edi | |
60 | convert_predefinition: | |
61 | cmp edi,[memory_end] | |
62 | jae out_of_memory | |
63 | lods byte [esi] | |
64 | or al,al | |
65 | jz predefinition_converted | |
66 | cmp al,20h | |
67 | je convert_predefinition | |
68 | mov ah,al | |
69 | mov ebx,characters | |
70 | xlat byte [ebx] | |
71 | or al,al | |
72 | jz predefinition_separator | |
73 | cmp ah,27h | |
74 | je predefinition_string | |
75 | cmp ah,22h | |
76 | je predefinition_string | |
77 | mov byte [edi],1Ah | |
78 | scas word [edi] | |
79 | xchg al,ah | |
80 | stos byte [edi] | |
81 | mov ebx,characters | |
82 | xor ecx,ecx | |
83 | predefinition_symbol: | |
84 | lods byte [esi] | |
85 | stos byte [edi] | |
86 | xlat byte [ebx] | |
87 | or al,al | |
88 | loopnzd predefinition_symbol | |
89 | neg ecx | |
90 | cmp ecx,255 | |
91 | ja invalid_definition | |
92 | mov ebx,edi | |
93 | sub ebx,ecx | |
94 | mov byte [ebx-2],cl | |
95 | found_predefinition_separator: | |
96 | dec edi | |
97 | mov ah,[esi-1] | |
98 | predefinition_separator: | |
99 | xchg al,ah | |
100 | or al,al | |
101 | jz predefinition_converted | |
102 | cmp al,20h | |
103 | je convert_line_data | |
104 | cmp al,3Bh | |
105 | je invalid_definition | |
106 | cmp al,5Ch | |
107 | je predefinition_backslash | |
108 | stos byte [edi] | |
109 | jmp convert_predefinition | |
110 | predefinition_string: | |
111 | mov al,22h | |
112 | stos byte [edi] | |
113 | scas dword [edi] | |
114 | mov ebx,edi | |
115 | copy_predefinition_string: | |
116 | lods byte [esi] | |
117 | stos byte [edi] | |
118 | or al,al | |
119 | jz invalid_definition | |
120 | cmp al,ah | |
121 | jne copy_predefinition_string | |
122 | lods byte [esi] | |
123 | cmp al,ah | |
124 | je copy_predefinition_string | |
125 | dec esi | |
126 | dec edi | |
127 | mov eax,edi | |
128 | sub eax,ebx | |
129 | mov [ebx-4],eax | |
130 | jmp convert_predefinition | |
131 | predefinition_backslash: | |
132 | mov byte [edi],0 | |
133 | lods byte [esi] | |
134 | or al,al | |
135 | jz invalid_definition | |
136 | cmp al,20h | |
137 | je invalid_definition | |
138 | cmp al,3Bh | |
139 | je invalid_definition | |
140 | mov al,1Ah | |
141 | stos byte [edi] | |
142 | mov ecx,edi | |
143 | mov ax,5C01h | |
144 | stos word [edi] | |
145 | dec esi | |
146 | group_predefinition_backslashes: | |
147 | lods byte [esi] | |
148 | cmp al,5Ch | |
149 | jne predefinition_backslashed_symbol | |
150 | stos byte [edi] | |
151 | inc byte [ecx] | |
152 | jmp group_predefinition_backslashes | |
153 | predefinition_backslashed_symbol: | |
154 | cmp al,20h | |
155 | je invalid_definition | |
156 | cmp al,22h | |
157 | je invalid_definition | |
158 | cmp al,27h | |
159 | je invalid_definition | |
160 | cmp al,3Bh | |
161 | je invalid_definition | |
162 | mov ah,al | |
163 | mov ebx,characters | |
164 | xlat byte [ebx] | |
165 | or al,al | |
166 | jz predefinition_backslashed_symbol_character | |
167 | mov al,ah | |
168 | convert_predefinition_backslashed_symbol: | |
169 | stos byte [edi] | |
170 | xlat byte [ebx] | |
171 | or al,al | |
172 | jz found_predefinition_separator | |
173 | inc byte [ecx] | |
174 | jz invalid_definition | |
175 | lods byte [esi] | |
176 | jmp convert_predefinition_backslashed_symbol | |
177 | predefinition_backslashed_symbol_character: | |
178 | mov al,ah | |
179 | stos byte [edi] | |
180 | inc byte [ecx] | |
181 | jmp convert_predefinition | |
182 | predefinition_converted: | |
183 | mov [memory_start],edi | |
184 | sub edi,[edx+8] | |
185 | mov [edx+12],edi | |
186 | jmp process_predefinitions | |
187 | predefinitions_ok: | |
44 | 188 | mov esi,[input_file] |
45 | 189 | mov edx,esi |
46 | 190 | call open |
77 | 221 | mov [ebx],eax |
78 | 222 | call use_postponed_macro |
79 | 223 | pop edx |
80 | jmp process_postponed_list | |
224 | cmp [macro_status],0 | |
225 | je process_postponed_list | |
226 | mov eax,[error_line] | |
227 | mov [current_line],eax | |
228 | jmp incomplete_macro | |
81 | 229 | preprocessing_finished: |
82 | 230 | mov [source_start],edi |
83 | 231 | ret |
274 | 422 | jne backslashed_symbol |
275 | 423 | stos byte [edi] |
276 | 424 | inc byte [ecx] |
425 | jz name_too_long | |
277 | 426 | jmp group_backslashes |
278 | 427 | no_end_quote: |
279 | 428 | mov byte [ebx-5],0 |
895 | 1044 | inc esi |
896 | 1045 | add esi,eax |
897 | 1046 | lods byte [esi] |
1047 | cmp al,':' | |
1048 | je macro_argument_with_default_value | |
898 | 1049 | cmp al,'=' |
899 | 1050 | je macro_argument_with_default_value |
900 | 1051 | cmp al,'*' |
903 | 1054 | macro_argument_end: |
904 | 1055 | cmp al,',' |
905 | 1056 | je skip_macro_arguments |
1057 | cmp al,'&' | |
1058 | je macro_arguments_finisher | |
906 | 1059 | cmp al,']' |
907 | 1060 | jne end_macro_arguments |
908 | lods byte [esi] | |
909 | 1061 | not ebp |
1062 | macro_arguments_finisher: | |
1063 | lods byte [esi] | |
910 | 1064 | end_macro_arguments: |
911 | 1065 | or ebp,ebp |
912 | 1066 | jnz invalid_macro_arguments |
916 | 1070 | je found_macro_block |
917 | 1071 | jmp invalid_macro_arguments |
918 | 1072 | macro_argument_with_default_value: |
919 | or [default_argument_value],-1 | |
1073 | or [skip_default_argument_value],-1 | |
920 | 1074 | call skip_macro_argument_value |
921 | 1075 | inc esi |
922 | 1076 | jmp macro_argument_end |
955 | 1109 | jz argument_value_end |
956 | 1110 | cmp al,',' |
957 | 1111 | je argument_value_end |
958 | cmp [default_argument_value],0 | |
1112 | cmp [skip_default_argument_value],0 | |
959 | 1113 | je invalid_macro_arguments |
960 | 1114 | cmp al,'{' |
1115 | je argument_value_end | |
1116 | cmp al,'&' | |
961 | 1117 | je argument_value_end |
962 | 1118 | or ebp,ebp |
963 | 1119 | jz invalid_macro_arguments |
974 | 1130 | je argument_string |
975 | 1131 | cmp al,1Ah |
976 | 1132 | je argument_symbol |
977 | cmp [default_argument_value],0 | |
1133 | cmp [skip_default_argument_value],0 | |
978 | 1134 | je simple_argument |
979 | 1135 | cmp al,'{' |
1136 | je argument_value_end | |
1137 | cmp al,'&' | |
980 | 1138 | je argument_value_end |
981 | 1139 | or ebp,ebp |
982 | 1140 | jz simple_argument |
1055 | 1213 | xor ecx,ecx |
1056 | 1214 | call add_preprocessor_symbol |
1057 | 1215 | mov eax,[current_line] |
1216 | mov [error_line],eax | |
1058 | 1217 | mov [edx+12],eax |
1059 | 1218 | pop esi |
1060 | 1219 | mov [edx+8],esi |
1062 | 1221 | and al,0F0h |
1063 | 1222 | or al,1 |
1064 | 1223 | mov [macro_status],al |
1065 | mov eax,[current_line] | |
1066 | mov [error_line],eax | |
1067 | 1224 | lods byte [esi] |
1068 | 1225 | or al,al |
1069 | 1226 | jz line_preprocessed |
1557 | 1714 | je next_argument |
1558 | 1715 | cmp al,']' |
1559 | 1716 | je next_arguments_group |
1717 | cmp al,'&' | |
1718 | je arguments_end | |
1560 | 1719 | dec esi |
1561 | 1720 | jmp arguments_end |
1562 | 1721 | next_argument: |
1577 | 1736 | mov eax,[counter_limit] |
1578 | 1737 | call add_macro_symbol |
1579 | 1738 | add esi,ecx |
1739 | xor eax,eax | |
1740 | mov [default_argument_value],eax | |
1741 | cmp byte [esi],'*' | |
1742 | je required_value | |
1743 | cmp byte [esi],':' | |
1744 | je get_default_value | |
1745 | cmp byte [esi],'=' | |
1746 | jne default_value_ok | |
1747 | get_default_value: | |
1748 | inc esi | |
1749 | mov [default_argument_value],esi | |
1750 | or [skip_default_argument_value],-1 | |
1751 | call skip_macro_argument_value | |
1752 | jmp default_value_ok | |
1753 | required_value: | |
1754 | inc esi | |
1755 | or [default_argument_value],-1 | |
1756 | default_value_ok: | |
1580 | 1757 | xchg esi,ebx |
1581 | 1758 | mov [edx+12],esi |
1582 | mov [default_argument_value],0 | |
1759 | mov [skip_default_argument_value],0 | |
1760 | cmp byte [ebx],'&' | |
1761 | je greedy_macro_argument | |
1583 | 1762 | call skip_macro_argument_value |
1584 | 1763 | call finish_macro_argument |
1764 | jmp got_macro_argument | |
1765 | greedy_macro_argument: | |
1766 | call skip_foreign_line | |
1767 | dec esi | |
1768 | mov eax,[edx+12] | |
1769 | mov ecx,esi | |
1770 | sub ecx,eax | |
1771 | mov [edx+8],ecx | |
1772 | got_macro_argument: | |
1585 | 1773 | xchg esi,ebx |
1586 | cmp byte [esi],'=' | |
1587 | je argument_with_default_value | |
1588 | cmp byte [esi],'*' | |
1774 | cmp dword [edx+8],0 | |
1589 | 1775 | jne macro_argument_ok |
1590 | cmp dword [edx+8],0 | |
1776 | mov eax,[default_argument_value] | |
1777 | or eax,eax | |
1778 | jz macro_argument_ok | |
1779 | cmp eax,-1 | |
1591 | 1780 | je invalid_macro_arguments |
1592 | inc esi | |
1781 | mov [edx+12],eax | |
1782 | call finish_macro_argument | |
1593 | 1783 | macro_argument_ok: |
1594 | 1784 | ret |
1595 | 1785 | finish_macro_argument: |
1604 | 1794 | argument_value_length_ok: |
1605 | 1795 | mov [edx+8],ecx |
1606 | 1796 | ret |
1607 | argument_with_default_value: | |
1608 | inc esi | |
1609 | push esi | |
1610 | or [default_argument_value],-1 | |
1611 | call skip_macro_argument_value | |
1612 | pop eax | |
1613 | cmp dword [edx+8],0 | |
1614 | jne macro_argument_ok | |
1615 | mov [edx+12],eax | |
1616 | call finish_macro_argument | |
1617 | jmp macro_argument_ok | |
1618 | 1797 | arguments_end: |
1619 | 1798 | cmp byte [ebx],0 |
1620 | 1799 | jne invalid_macro_arguments |
1740 | 1919 | lods byte [esi] |
1741 | 1920 | cmp [base_code],1 |
1742 | 1921 | ja irps_name_ok |
1922 | cmp al,':' | |
1923 | je irp_with_default_value | |
1743 | 1924 | cmp al,'=' |
1744 | 1925 | je irp_with_default_value |
1745 | 1926 | cmp al,'*' |
1751 | 1932 | jmp irp_parameters_start |
1752 | 1933 | irp_with_default_value: |
1753 | 1934 | xor ebp,ebp |
1754 | or [default_argument_value],-1 | |
1935 | or [skip_default_argument_value],-1 | |
1755 | 1936 | call skip_macro_argument_value |
1937 | cmp byte [esi],',' | |
1938 | jne invalid_macro_arguments | |
1756 | 1939 | inc esi |
1757 | 1940 | jmp irp_parameters_start |
1758 | 1941 | irps_name_ok: |
0 | 0 | |
1 | 1 | ; flat assembler core |
2 | ; Copyright (c) 1999-2014, Tomasz Grysztar. | |
2 | ; Copyright (c) 1999-2015, Tomasz Grysztar. | |
3 | 3 | ; All rights reserved. |
4 | 4 | |
5 | 5 | dump_symbols: |
0 | 0 | |
1 | 1 | ; flat assembler core |
2 | ; Copyright (c) 1999-2014, Tomasz Grysztar. | |
2 | ; Copyright (c) 1999-2015, Tomasz Grysztar. | |
3 | 3 | ; All rights reserved. |
4 | 4 | |
5 | 5 | include_variable db 'INCLUDE',0 |
63 | 63 | single_operand_operators: |
64 | 64 | db 1,'+',82h |
65 | 65 | db 1,'-',83h |
66 | db 3,'bsf',0E0h | |
67 | db 3,'bsr',0E1h | |
66 | 68 | db 3,'not',0D0h |
67 | db 3,'plt',0E1h | |
68 | db 3,'rva',0E0h | |
69 | db 3,'plt',0F1h | |
70 | db 3,'rva',0F0h | |
69 | 71 | db 0 |
70 | 72 | |
71 | 73 | directive_operators: |
0 | 0 | |
1 | 1 | ; flat assembler core variables |
2 | ; Copyright (c) 1999-2014, Tomasz Grysztar. | |
2 | ; Copyright (c) 1999-2015, Tomasz Grysztar. | |
3 | 3 | ; All rights reserved. |
4 | 4 | |
5 | 5 | ; Variables which have to be set up by interface: |
12 | 12 | |
13 | 13 | stack_limit dd ? |
14 | 14 | |
15 | initial_definitions dd ? | |
15 | 16 | input_file dd ? |
16 | 17 | output_file dd ? |
17 | 18 | symbols_file dd ? |
41 | 42 | struc_label dd ? |
42 | 43 | instant_macro_start dd ? |
43 | 44 | parameters_end dd ? |
45 | default_argument_value dd ? | |
44 | 46 | locals_counter rb 8 |
45 | 47 | current_locals_prefix dd ? |
46 | 48 | anonymous_reverse dd ? |
132 | 134 | adjustment_sign db ? |
133 | 135 | |
134 | 136 | macro_status db ? |
135 | default_argument_value db ? | |
137 | skip_default_argument_value db ? | |
136 | 138 | prefixed_instruction db ? |
137 | 139 | formatter_symbols_allowed db ? |
138 | 140 | free_address_range db ? |
0 | 0 | |
1 | 1 | ; flat assembler version 1.71 |
2 | ; Copyright (c) 1999-2014, Tomasz Grysztar. | |
2 | ; Copyright (c) 1999-2015, Tomasz Grysztar. | |
3 | 3 | ; All rights reserved. |
4 | 4 | ; |
5 | 5 | ; This programs is free for commercial and non-commercial use as long as |
32 | 32 | ; cannot simply be copied and put under another distribution licence |
33 | 33 | ; (including the GNU Public Licence). |
34 | 34 | |
35 | VERSION_STRING equ "1.71.22" | |
35 | VERSION_STRING equ "1.71.39" | |
36 | 36 | |
37 | 37 | VERSION_MAJOR = 1 |
38 | 38 | VERSION_MINOR = 71 |
0 | 0 | |
1 | 1 | ; flat assembler core |
2 | ; Copyright (c) 1999-2014, Tomasz Grysztar. | |
2 | ; Copyright (c) 1999-2015, Tomasz Grysztar. | |
3 | 3 | ; All rights reserved. |
4 | 4 | |
5 | 5 | simple_instruction_except64: |
555 | 555 | cmp [value_type],4 |
556 | 556 | jae long_immediate_not_encodable |
557 | 557 | jmp mov_mem_imm_32bit_store |
558 | mov_mem_imm_nosize: | |
559 | call recoverable_unknown_size | |
558 | 560 | mov_mem_imm_8bit: |
559 | 561 | call get_byte_value |
560 | 562 | mov byte [value],al |
572 | 574 | pop ecx ebx edx |
573 | 575 | call store_instruction_with_imm16 |
574 | 576 | jmp instruction_assembled |
575 | mov_mem_imm_nosize: | |
576 | call recoverable_unknown_size | |
577 | 577 | mov_mem_imm_32bit: |
578 | 578 | call operand_32bit |
579 | 579 | call get_dword_value |
965 | 965 | cmp [value_type],4 |
966 | 966 | jae long_immediate_not_encodable |
967 | 967 | jmp test_mem_imm_32bit_store |
968 | test_mem_imm_nosize: | |
969 | call recoverable_unknown_size | |
968 | 970 | test_mem_imm_8bit: |
969 | 971 | call get_byte_value |
970 | 972 | mov byte [value],al |
982 | 984 | pop ecx ebx edx |
983 | 985 | call store_instruction_with_imm16 |
984 | 986 | jmp instruction_assembled |
985 | test_mem_imm_nosize: | |
986 | call recoverable_unknown_size | |
987 | 987 | test_mem_imm_32bit: |
988 | 988 | call operand_32bit |
989 | 989 | call get_dword_value |
4610 | 4610 | call get_size_operator |
4611 | 4611 | cmp al,10h |
4612 | 4612 | je movq_mmreg_reg |
4613 | cmp al,'[' | |
4614 | jne invalid_operand | |
4613 | 4615 | call get_address |
4614 | 4616 | test [operand_size],not 8 |
4615 | 4617 | jnz invalid_operand_size |
0 | 0 | |
1 | 1 | Visit http://flatassembler.net/ for more information. |
2 | ||
3 | ||
4 | version 1.71.39 (Mar 11, 2015) | |
5 | ||
6 | [-] Minor bug fix. | |
7 | ||
8 | ||
9 | version 1.71.38 (Mar 09, 2015) | |
10 | ||
11 | [-] Minor bug fixes. | |
12 | ||
13 | ||
14 | version 1.71.37 (Mar 03, 2015) | |
15 | ||
16 | [-] Fixed a crash caused by incorrect handling of any error in definition | |
17 | provided through "-d" switch. | |
18 | ||
19 | ||
20 | version 1.71.36 (Feb 26, 2015) | |
21 | ||
22 | [-] Fixed a small bug with "irp" directive. | |
23 | ||
24 | ||
25 | version 1.71.35 (Feb 25, 2015) | |
26 | ||
27 | [-] Corrected a flaw that caused a crash when processing incomplete macro | |
28 | definitions within the "postpone" block. | |
29 | ||
30 | ||
31 | version 1.71.34 (Feb 17, 2015) | |
32 | ||
33 | [-] Fixed a recently introduced bug that caused assembler to hang when a | |
34 | missing closing parenthesis error was encountered. | |
35 | ||
36 | ||
37 | version 1.71.33 (Jan 09, 2015) | |
38 | ||
39 | [+] Default value for macroinstruction parameter can now be defined with ":" | |
40 | character as an alternative to "=". | |
41 | ||
42 | ||
43 | version 1.71.32 (Jan 04, 2015) | |
44 | ||
45 | [+] Brought back the "-d" switch for command line. | |
46 | ||
47 | ||
48 | version 1.71.31 (Dec 08, 2014) | |
49 | ||
50 | [-] Removed dependence on size context for expression operators like NOT and XOR. | |
51 | ||
52 | [-] Relaxed range checking to allow extended negative range for all sizes. | |
53 | ||
54 | ||
55 | version 1.71.30 (Dec 07, 2014) | |
56 | ||
57 | [-] Clearing the instruction data field when filling the addend for 64-bit ELF | |
58 | relocaiton. | |
59 | ||
60 | ||
61 | version 1.71.29 (Dec 05, 2014) | |
62 | ||
63 | [-] Supressed error message when parsing some malformed expressions that do not | |
64 | get evaluated. | |
65 | ||
66 | ||
67 | version 1.71.28 (Dec 01, 2014) | |
68 | ||
69 | [-] The addend field of relocation structure for 64-bit ELF format is now filled with | |
70 | correct information. | |
71 | ||
72 | ||
73 | version 1.71.27 (Nov 18, 2014) | |
74 | ||
75 | [-] Corrected initial predictions of immediate size for "mov" and "test" instructions | |
76 | (this may sometimes help to generate smaller code). | |
77 | ||
78 | ||
79 | version 1.71.26 (Nov 12, 2014) | |
80 | ||
81 | [-] Fixed a bug introduced by previous version that allowed address values to | |
82 | bypass range checks. | |
83 | ||
84 | ||
85 | version 1.71.25 (Nov 03, 2014) | |
86 | ||
87 | [-] Fixed a bug that cause valued of argument starting with "<" character to be | |
88 | incorrectly processed when the parameter in question was marked with "&" | |
89 | character. | |
90 | ||
91 | ||
92 | version 1.71.24 (Oct 27, 2014) | |
93 | ||
94 | [+] In the definition of macroinstruction the last argument can now be followed by | |
95 | "&" character to indicate that this argument can be filled with all the remaining | |
96 | contents of line that called the macro. This feature cannot be combined with a | |
97 | multi-value arguments. | |
98 | ||
99 | ||
100 | version 1.71.23 (Oct 21, 2014) | |
101 | ||
102 | [+] Added "bsf" and "bsr" operators to numerical expressions. | |
103 | ||
104 | [-] Removed the restriction that disallowed numerical constant to | |
105 | forward-reference its own value. | |
2 | 106 | |
3 | 107 | |
4 | 108 | version 1.71.22 (Sep 28, 2014) |