"Fossies" - the Fresh Open Source Software Archive

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