"Fossies" - the Fresh Open Source Software Archive

Member "fasm/tools/win32/listing.asm" (9 Feb 2020, 3778 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.

    1 
    2 format PE console 4.0
    3 entry start
    4 
    5 include 'win32a.inc'
    6 
    7 section '.data' data readable writeable
    8 
    9   _usage db 'listing generator for flat assembler',0Dh,0Ah
   10      db 'usage: listing <input> <output>',0Dh,0Ah
   11      db 'optional settings:',0Dh,0Ah
   12      db ' -a           show target addresses for assembled code',0Dh,0Ah
   13      db ' -b <number>  set the amount of bytes listed per line',0Dh,0Ah
   14      db 0
   15   _error_prefix db 'error: ',0
   16   _error_suffix db '.',0Dh,0Ah,0
   17 
   18   line_break db 0Dh,0Ah
   19 
   20   input_file dd 0
   21   output_file dd 0
   22   code_bytes_per_line dd 16
   23   show_addresses db 0
   24 
   25   input dd ?
   26   assembled_code dd ?
   27   assembled_code_length dd ?
   28   code_end dd ?
   29   code_offset dd ?
   30   code_length dd ?
   31   output_handle dd ?
   32   output_buffer dd ?
   33   current_source_file dd ?
   34   current_source_line dd ?
   35   source dd ?
   36   source_length dd ?
   37   maximum_address_length dd ?
   38   address_start dd ?
   39   last_listed_address dd ?
   40 
   41   display_handle dd ?
   42   bytes_count dd ?
   43 
   44   params rb 1000h
   45   characters rb 100h
   46 
   47 section '.text' code readable executable
   48 
   49   start:
   50 
   51     mov [display_handle],STD_OUTPUT_HANDLE
   52 
   53     call    get_params
   54     jnc make_listing
   55 
   56     mov esi,_usage
   57     call    display_string
   58     invoke  ExitProcess,2
   59 
   60   make_listing:
   61     call    listing
   62     invoke  ExitProcess,0
   63 
   64   error:
   65     mov [display_handle],STD_ERROR_HANDLE
   66     mov esi,_error_prefix
   67     call    display_string
   68     pop esi
   69     call    display_string
   70     mov esi,_error_suffix
   71     call    display_string
   72     invoke  ExitProcess,1
   73 
   74   get_params:
   75     invoke  GetCommandLine
   76     mov esi,eax
   77     mov edi,params
   78     find_command_start:
   79     lodsb
   80     cmp al,20h
   81     je  find_command_start
   82     cmp al,22h
   83     je  skip_quoted_name
   84     skip_name:
   85     lodsb
   86     cmp al,20h
   87     je  find_param
   88     or  al,al
   89     jz  all_params
   90     jmp skip_name
   91     skip_quoted_name:
   92     lodsb
   93     cmp al,22h
   94     je  find_param
   95     or  al,al
   96     jz  all_params
   97     jmp skip_quoted_name
   98     find_param:
   99     lodsb
  100     cmp al,20h
  101     je  find_param
  102     cmp al,'-'
  103     je  option_param
  104     cmp al,0Dh
  105     je  all_params
  106     or  al,al
  107     jz  all_params
  108     cmp [input_file],0
  109     jne get_output_file
  110     mov [input_file],edi
  111     jmp process_param
  112       get_output_file:
  113     cmp [output_file],0
  114     jne bad_params
  115     mov [output_file],edi
  116     process_param:
  117     cmp al,22h
  118     je  string_param
  119     copy_param:
  120     stosb
  121     lodsb
  122     cmp al,20h
  123     je  param_end
  124     cmp al,0Dh
  125     je  param_end
  126     or  al,al
  127     jz  param_end
  128     jmp copy_param
  129     string_param:
  130     lodsb
  131     cmp al,22h
  132     je  string_param_end
  133     cmp al,0Dh
  134     je  param_end
  135     or  al,al
  136     jz  param_end
  137     stosb
  138     jmp string_param
  139     option_param:
  140     lodsb
  141     cmp al,'a'
  142     je  addresses_option
  143     cmp al,'A'
  144     je  addresses_option
  145     cmp al,'b'
  146     je  bytes_per_line_option
  147     cmp al,'B'
  148     je  bytes_per_line_option
  149     bad_params:
  150     stc
  151     ret
  152     get_option_value:
  153     xor eax,eax
  154     mov edx,eax
  155     get_option_digit:
  156     lodsb
  157     cmp al,20h
  158     je  option_value_ok
  159     cmp al,0Dh
  160     je  option_value_ok
  161     or  al,al
  162     jz  option_value_ok
  163     sub al,30h
  164     jc  invalid_option_value
  165     cmp al,9
  166     ja  invalid_option_value
  167     imul    edx,10
  168     jo  invalid_option_value
  169     add edx,eax
  170     jc  invalid_option_value
  171     jmp get_option_digit
  172     option_value_ok:
  173     dec esi
  174     clc
  175     ret
  176     invalid_option_value:
  177     stc
  178     ret
  179     bytes_per_line_option:
  180     lodsb
  181     cmp al,20h
  182     je  bytes_per_line_option
  183     cmp al,0Dh
  184     je  bad_params
  185     or  al,al
  186     jz  bad_params
  187     dec esi
  188     call    get_option_value
  189     or  edx,edx
  190     jz  bad_params
  191     cmp edx,1000
  192     ja  bad_params
  193     mov [code_bytes_per_line],edx
  194     jmp find_param
  195     addresses_option:
  196     lodsb
  197     cmp al,20h
  198     je  set_addresses_option
  199     cmp al,0Dh
  200     je  set_addresses_option
  201     or  al,al
  202     jnz bad_params
  203       set_addresses_option:
  204     dec esi
  205     mov [show_addresses],1
  206     jmp find_param
  207     param_end:
  208     dec esi
  209     string_param_end:
  210     xor al,al
  211     stosb
  212     jmp find_param
  213     all_params:
  214     cmp [input_file],0
  215     je  bad_params
  216     cmp [output_file],0
  217     je  bad_params
  218     clc
  219     ret
  220 
  221   include 'system.inc'
  222 
  223   include '..\listing.inc'
  224 
  225 section '.idata' import data readable writeable
  226 
  227   library kernel32,'KERNEL32.DLL'
  228 
  229   include 'api\kernel32.inc'