"Fossies" - the Fresh Open Source Software Archive

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