"Fossies" - the Fresh Open Source Software Archive

Member "fasm/source/Win32/fasm.asm" (9 Feb 2020, 8205 Bytes) of package /linux/misc/fasm-1.73.22.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.21_vs_1.73.22.

    1 
    2 ; flat assembler interface for Win32
    3 ; Copyright (c) 1999-2020, Tomasz Grysztar.
    4 ; All rights reserved.
    5 
    6     format  PE console
    7 
    8 section '.text' code readable executable
    9 
   10 start:
   11 
   12     mov [con_handle],STD_OUTPUT_HANDLE
   13     mov esi,_logo
   14     call    display_string
   15 
   16     call    get_params
   17     jc  information
   18 
   19     call    init_memory
   20 
   21     mov esi,_memory_prefix
   22     call    display_string
   23     mov eax,[memory_end]
   24     sub eax,[memory_start]
   25     add eax,[additional_memory_end]
   26     sub eax,[additional_memory]
   27     shr eax,10
   28     call    display_number
   29     mov esi,_memory_suffix
   30     call    display_string
   31 
   32     call    [GetTickCount]
   33     mov [start_time],eax
   34 
   35     and [preprocessing_done],0
   36     call    preprocessor
   37     or  [preprocessing_done],-1
   38     call    parser
   39     call    assembler
   40     call    formatter
   41 
   42     call    display_user_messages
   43     movzx   eax,[current_pass]
   44     inc eax
   45     call    display_number
   46     mov esi,_passes_suffix
   47     call    display_string
   48     call    [GetTickCount]
   49     sub eax,[start_time]
   50     xor edx,edx
   51     mov ebx,100
   52     div ebx
   53     or  eax,eax
   54     jz  display_bytes_count
   55     xor edx,edx
   56     mov ebx,10
   57     div ebx
   58     push    edx
   59     call    display_number
   60     mov dl,'.'
   61     call    display_character
   62     pop eax
   63     call    display_number
   64     mov esi,_seconds_suffix
   65     call    display_string
   66       display_bytes_count:
   67     mov eax,[written_size]
   68     call    display_number
   69     mov esi,_bytes_suffix
   70     call    display_string
   71     xor al,al
   72     jmp exit_program
   73 
   74 information:
   75     mov esi,_usage
   76     call    display_string
   77     mov al,1
   78     jmp exit_program
   79 
   80 get_params:
   81     mov [input_file],0
   82     mov [output_file],0
   83     mov [symbols_file],0
   84     mov [memory_setting],0
   85     mov [passes_limit],100
   86     call    [GetCommandLine]
   87     mov [definitions_pointer],predefinitions
   88     mov esi,eax
   89     mov edi,params
   90     find_command_start:
   91     lodsb
   92     cmp al,20h
   93     je  find_command_start
   94     cmp al,22h
   95     je  skip_quoted_name
   96     skip_name:
   97     lodsb
   98     cmp al,20h
   99     je  find_param
  100     or  al,al
  101     jz  all_params
  102     jmp skip_name
  103     skip_quoted_name:
  104     lodsb
  105     cmp al,22h
  106     je  find_param
  107     or  al,al
  108     jz  all_params
  109     jmp skip_quoted_name
  110     find_param:
  111     lodsb
  112     cmp al,20h
  113     je  find_param
  114     cmp al,'-'
  115     je  option_param
  116     cmp al,0Dh
  117     je  all_params
  118     or  al,al
  119     jz  all_params
  120     cmp [input_file],0
  121     jne get_output_file
  122     mov [input_file],edi
  123     jmp process_param
  124       get_output_file:
  125     cmp [output_file],0
  126     jne bad_params
  127     mov [output_file],edi
  128     process_param:
  129     cmp al,22h
  130     je  string_param
  131     copy_param:
  132     cmp edi,params+1000h
  133     jae bad_params
  134     stosb
  135     lodsb
  136     cmp al,20h
  137     je  param_end
  138     cmp al,0Dh
  139     je  param_end
  140     or  al,al
  141     jz  param_end
  142     jmp copy_param
  143     string_param:
  144     lodsb
  145     cmp al,22h
  146     je  string_param_end
  147     cmp al,0Dh
  148     je  param_end
  149     or  al,al
  150     jz  param_end
  151     cmp edi,params+1000h
  152     jae bad_params
  153     stosb
  154     jmp string_param
  155     option_param:
  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     get_option_value:
  177     xor eax,eax
  178     mov edx,eax
  179     get_option_digit:
  180     lodsb
  181     cmp al,20h
  182     je  option_value_ok
  183     cmp al,0Dh
  184     je  option_value_ok
  185     or  al,al
  186     jz  option_value_ok
  187     sub al,30h
  188     jc  invalid_option_value
  189     cmp al,9
  190     ja  invalid_option_value
  191     imul    edx,10
  192     jo  invalid_option_value
  193     add edx,eax
  194     jc  invalid_option_value
  195     jmp get_option_digit
  196     option_value_ok:
  197     dec esi
  198     clc
  199     ret
  200     invalid_option_value:
  201     stc
  202     ret
  203     memory_option:
  204     lodsb
  205     cmp al,20h
  206     je  memory_option
  207     cmp al,0Dh
  208     je  bad_params
  209     or  al,al
  210     jz  bad_params
  211     dec esi
  212     call    get_option_value
  213     or  edx,edx
  214     jz  bad_params
  215     cmp edx,1 shl (32-10)
  216     jae bad_params
  217     mov [memory_setting],edx
  218     jmp find_param
  219     passes_option:
  220     lodsb
  221     cmp al,20h
  222     je  passes_option
  223     cmp al,0Dh
  224     je  bad_params
  225     or  al,al
  226     jz  bad_params
  227     dec esi
  228     call    get_option_value
  229     or  edx,edx
  230     jz  bad_params
  231     cmp edx,10000h
  232     ja  bad_params
  233     mov [passes_limit],dx
  234     jmp find_param
  235     definition_option:
  236     lodsb
  237     cmp al,20h
  238     je  definition_option
  239     cmp al,0Dh
  240     je  bad_params
  241     or  al,al
  242     jz  bad_params
  243     dec esi
  244     push    edi
  245     mov edi,[definitions_pointer]
  246     call    convert_definition_option
  247     mov [definitions_pointer],edi
  248     pop edi
  249     jc  bad_params
  250     jmp find_param
  251     symbols_option:
  252     mov [symbols_file],edi
  253       find_symbols_file_name:
  254     lodsb
  255     cmp al,20h
  256     jne process_param
  257     jmp find_symbols_file_name
  258     param_end:
  259     dec esi
  260     string_param_end:
  261     cmp edi,params+1000h
  262     jae bad_params
  263     xor al,al
  264     stosb
  265     jmp find_param
  266     all_params:
  267     cmp [input_file],0
  268     je  bad_params
  269     mov eax,[definitions_pointer]
  270     mov byte [eax],0
  271     mov [initial_definitions],predefinitions
  272     clc
  273     ret
  274     convert_definition_option:
  275     mov ecx,edi
  276     cmp edi,predefinitions+1000h
  277     jae bad_definition_option
  278     xor al,al
  279     stosb
  280       copy_definition_name:
  281     lodsb
  282     cmp al,'='
  283     je  copy_definition_value
  284     cmp al,20h
  285     je  bad_definition_option
  286     cmp al,0Dh
  287     je  bad_definition_option
  288     or  al,al
  289     jz  bad_definition_option
  290     cmp edi,predefinitions+1000h
  291     jae bad_definition_option
  292     stosb
  293     inc byte [ecx]
  294     jnz copy_definition_name
  295       bad_definition_option:
  296     stc
  297     ret
  298       copy_definition_value:
  299     lodsb
  300     cmp al,20h
  301     je  definition_value_end
  302     cmp al,0Dh
  303     je  definition_value_end
  304     or  al,al
  305     jz  definition_value_end
  306     cmp al,'\'
  307     jne definition_value_character
  308     cmp byte [esi],20h
  309     jne definition_value_character
  310     lodsb
  311       definition_value_character:
  312     cmp edi,predefinitions+1000h
  313     jae bad_definition_option
  314     stosb
  315     jmp copy_definition_value
  316       definition_value_end:
  317     dec esi
  318     cmp edi,predefinitions+1000h
  319     jae bad_definition_option
  320     xor al,al
  321     stosb
  322     clc
  323     ret
  324 
  325 include 'system.inc'
  326 
  327 include '..\errors.inc'
  328 include '..\symbdump.inc'
  329 include '..\preproce.inc'
  330 include '..\parser.inc'
  331 include '..\exprpars.inc'
  332 include '..\assemble.inc'
  333 include '..\exprcalc.inc'
  334 include '..\formats.inc'
  335 include '..\x86_64.inc'
  336 include '..\avx.inc'
  337 
  338 include '..\tables.inc'
  339 include '..\messages.inc'
  340 
  341 section '.data' data readable writeable
  342 
  343 include '..\version.inc'
  344 
  345 _copyright db 'Copyright (c) 1999-2020, Tomasz Grysztar',0Dh,0Ah,0
  346 
  347 _logo db 'flat assembler  version ',VERSION_STRING,0
  348 _usage db 0Dh,0Ah
  349        db 'usage: fasm <source> [output]',0Dh,0Ah
  350        db 'optional settings:',0Dh,0Ah
  351        db ' -m <limit>         set the limit in kilobytes for the available memory',0Dh,0Ah
  352        db ' -p <limit>         set the maximum allowed number of passes',0Dh,0Ah
  353        db ' -d <name>=<value>  define symbolic variable',0Dh,0Ah
  354        db ' -s <file>          dump symbolic information for debugging',0Dh,0Ah
  355        db 0
  356 _memory_prefix db '  (',0
  357 _memory_suffix db ' kilobytes memory)',0Dh,0Ah,0
  358 _passes_suffix db ' passes, ',0
  359 _seconds_suffix db ' seconds, ',0
  360 _bytes_suffix db ' bytes.',0Dh,0Ah,0
  361 
  362 align 4
  363 
  364 include '..\variable.inc'
  365 
  366 con_handle dd ?
  367 memory_setting dd ?
  368 start_time dd ?
  369 definitions_pointer dd ?
  370 bytes_count dd ?
  371 displayed_count dd ?
  372 character db ?
  373 last_displayed rb 2
  374 preprocessing_done db ?
  375 
  376 params rb 1000h
  377 options rb 1000h
  378 predefinitions rb 1000h
  379 buffer rb 4000h
  380 
  381 stack 10000h
  382 
  383 section '.idata' import data readable writeable
  384 
  385   dd 0,0,0,rva kernel_name,rva kernel_table
  386   dd 0,0,0,0,0
  387 
  388   kernel_table:
  389     ExitProcess dd rva _ExitProcess
  390     CreateFile dd rva _CreateFileA
  391     ReadFile dd rva _ReadFile
  392     WriteFile dd rva _WriteFile
  393     CloseHandle dd rva _CloseHandle
  394     SetFilePointer dd rva _SetFilePointer
  395     GetCommandLine dd rva _GetCommandLineA
  396     GetEnvironmentVariable dd rva _GetEnvironmentVariable
  397     GetStdHandle dd rva _GetStdHandle
  398     VirtualAlloc dd rva _VirtualAlloc
  399     VirtualFree dd rva _VirtualFree
  400     GetTickCount dd rva _GetTickCount
  401     GetSystemTime dd rva _GetSystemTime
  402     GlobalMemoryStatus dd rva _GlobalMemoryStatus
  403     dd 0
  404 
  405   kernel_name db 'KERNEL32.DLL',0
  406 
  407   _ExitProcess dw 0
  408     db 'ExitProcess',0
  409   _CreateFileA dw 0
  410     db 'CreateFileA',0
  411   _ReadFile dw 0
  412     db 'ReadFile',0
  413   _WriteFile dw 0
  414     db 'WriteFile',0
  415   _CloseHandle dw 0
  416     db 'CloseHandle',0
  417   _SetFilePointer dw 0
  418     db 'SetFilePointer',0
  419   _GetCommandLineA dw 0
  420     db 'GetCommandLineA',0
  421   _GetEnvironmentVariable dw 0
  422     db 'GetEnvironmentVariableA',0
  423   _GetStdHandle dw 0
  424     db 'GetStdHandle',0
  425   _VirtualAlloc dw 0
  426     db 'VirtualAlloc',0
  427   _VirtualFree dw 0
  428     db 'VirtualFree',0
  429   _GetTickCount dw 0
  430     db 'GetTickCount',0
  431   _GetSystemTime dw 0
  432     db 'GetSystemTime',0
  433   _GlobalMemoryStatus dw 0
  434     db 'GlobalMemoryStatus',0
  435 
  436 section '.reloc' fixups data readable discardable