"Fossies" - the Fresh Open Source Software Archive

Member "fasm/tools/dos/listing.asm" (21 Feb 2022, 3613 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.

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