"Fossies" - the Fresh Open Source Software Archive

Member "fasm/tools/libc/listing.asm" (21 Feb 2022, 2990 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  ELF
    3     public  main
    4 
    5 include 'ccall.inc'
    6 
    7 section '.text' executable align 16
    8 
    9   main:
   10     mov ecx,[esp+4]
   11     mov [argc],ecx
   12     mov ebx,[esp+8]
   13     mov [argv],ebx
   14 
   15     mov [display_handle],1
   16 
   17     call    get_params
   18     jnc make_listing
   19 
   20     mov esi,_usage
   21     call    display_string
   22     ccall   exit,2
   23 
   24   make_listing:
   25     call    listing
   26     ccall   exit,0
   27 
   28   error:
   29     mov [display_handle],2
   30     mov esi,_error_prefix
   31     call    display_string
   32     pop esi
   33     call    display_string
   34     mov esi,_error_suffix
   35     call    display_string
   36     ccall   exit,0
   37 
   38   get_params:
   39     mov ecx,[argc]
   40     mov ebx,[argv]
   41     add ebx,4
   42     dec ecx
   43     jz  bad_params
   44       get_param:
   45     mov esi,[ebx]
   46     mov al,[esi]
   47     cmp al,'-'
   48     je  option_param
   49     cmp [input_file],0
   50     jne get_output_file
   51     mov [input_file],esi
   52     jmp next_param
   53       get_output_file:
   54     cmp [output_file],0
   55     jne bad_params
   56     mov [output_file],esi
   57     jmp next_param
   58       option_param:
   59     inc esi
   60     lodsb
   61     cmp al,'a'
   62     je  addresses_option
   63     cmp al,'A'
   64     je  addresses_option
   65     cmp al,'b'
   66     je  bytes_per_line_option
   67     cmp al,'B'
   68     je  bytes_per_line_option
   69       bad_params:
   70     stc
   71     ret
   72       addresses_option:
   73     cmp byte [esi],0
   74     jne bad_params
   75     mov [show_addresses],1
   76     jmp next_param
   77       bytes_per_line_option:
   78     cmp byte [esi],0
   79     jne get_bytes_per_line_setting
   80     dec ecx
   81     jz  bad_params
   82     add ebx,4
   83     mov esi,[ebx]
   84       get_bytes_per_line_setting:
   85     call    get_option_value
   86     or  edx,edx
   87     jz  bad_params
   88     cmp edx,1000
   89     ja  bad_params
   90     mov [code_bytes_per_line],edx
   91       next_param:
   92     add ebx,4
   93     dec ecx
   94     jnz get_param
   95     cmp [input_file],0
   96     je  bad_params
   97     cmp [output_file],0
   98     je  bad_params
   99     clc
  100     ret
  101       get_option_value:
  102     xor eax,eax
  103     mov edx,eax
  104       get_option_digit:
  105     lodsb
  106     cmp al,20h
  107     je  option_value_ok
  108     cmp al,0Dh
  109     je  option_value_ok
  110     or  al,al
  111     jz  option_value_ok
  112     sub al,30h
  113     jc  invalid_option_value
  114     cmp al,9
  115     ja  invalid_option_value
  116     imul    edx,10
  117     jo  invalid_option_value
  118     add edx,eax
  119     jc  invalid_option_value
  120     jmp get_option_digit
  121       option_value_ok:
  122     dec esi
  123     clc
  124     ret
  125       invalid_option_value:
  126     stc
  127     ret
  128 
  129   include 'system.inc'
  130 
  131   include '..\listing.inc'
  132 
  133 section '.data' writeable align 4
  134 
  135   input_file dd 0
  136   output_file dd 0
  137   code_bytes_per_line dd 16
  138   show_addresses db 0
  139 
  140   line_break db 0Dh,0Ah
  141 
  142   _usage db 'listing generator for flat assembler',0Dh,0Ah
  143      db 'usage: listing <input> <output>',0Dh,0Ah
  144      db 'optional settings:',0Dh,0Ah
  145      db ' -a           show target addresses for assembled code',0Dh,0Ah
  146      db ' -b <number>  set the amount of bytes listed per line',0Dh,0Ah
  147      db 0
  148   _error_prefix db 'error: ',0
  149   _error_suffix db '.',0Dh,0Ah,0
  150 
  151 section '.bss' writeable align 4
  152 
  153   argc dd ?
  154   argv dd ?
  155 
  156   input dd ?
  157   assembled_code dd ?
  158   assembled_code_length dd ?
  159   code_end dd ?
  160   code_offset dd ?
  161   code_length dd ?
  162   output_handle dd ?
  163   output_buffer dd ?
  164   current_source_file dd ?
  165   current_source_line dd ?
  166   source dd ?
  167   source_length dd ?
  168   maximum_address_length dd ?
  169   address_start dd ?
  170   last_listed_address dd ?
  171 
  172   display_handle dd ?
  173   character db ?
  174 
  175   params rb 1000h
  176   characters rb 100h
  177   buffer rb 1000h