Subversion Repositories Kolibri OS

Rev

Rev 2287 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. ; flat assembler core
  3. ; Copyright (c) 1999-2012, Tomasz Grysztar.
  4. ; All rights reserved.
  5.  
  6. parser:
  7.         mov     eax,[memory_end]
  8.         mov     [labels_list],eax
  9.         mov     eax,[additional_memory]
  10.         mov     [free_additional_memory],eax
  11.         xor     eax,eax
  12.         mov     [current_locals_prefix],eax
  13.         mov     [anonymous_reverse],eax
  14.         mov     [anonymous_forward],eax
  15.         mov     [hash_tree],eax
  16.         mov     [blocks_stack],eax
  17.         mov     [parsed_lines],eax
  18.         mov     esi,[memory_start]
  19.         mov     edi,[source_start]
  20.       parser_loop:
  21.         mov     [current_line],esi
  22.         lea     eax,[edi+100h]
  23.         cmp     eax,[labels_list]
  24.         jae     out_of_memory
  25.         cmp     byte [esi+16],0
  26.         je      empty_line
  27.         cmp     byte [esi+16],3Bh
  28.         je      empty_line
  29.         mov     al,0Fh
  30.         stos    byte [edi]
  31.         mov     eax,esi
  32.         stos    dword [edi]
  33.         inc     [parsed_lines]
  34.         add     esi,16
  35.       parse_line:
  36.         mov     [formatter_symbols_allowed],0
  37.         cmp     byte [esi],1Ah
  38.         jne     empty_instruction
  39.         push    edi
  40.         add     esi,2
  41.         movzx   ecx,byte [esi-1]
  42.         cmp     byte [esi+ecx],':'
  43.         je      simple_label
  44.         cmp     byte [esi+ecx],'='
  45.         je      constant_label
  46.         call    get_instruction
  47.         jnc     main_instruction_identified
  48.         cmp     byte [esi+ecx],1Ah
  49.         jne     no_data_label
  50.         push    esi ecx
  51.         lea     esi,[esi+ecx+2]
  52.         movzx   ecx,byte [esi-1]
  53.         call    get_data_directive
  54.         jnc     data_label
  55.         pop     ecx esi
  56.       no_data_label:
  57.         call    get_data_directive
  58.         jnc     main_instruction_identified
  59.         pop     edi
  60.         sub     esi,2
  61.         xor     bx,bx
  62.         call    parse_line_contents
  63.         jmp     parse_next_line
  64.       simple_label:
  65.         pop     edi
  66.         call    identify_label
  67.         mov     byte [edi],2
  68.         inc     edi
  69.         stos    dword [edi]
  70.         inc     esi
  71.         xor     al,al
  72.         stos    byte [edi]
  73.         jmp     parse_line
  74.       constant_label:
  75.         pop     edi
  76.         call    get_label_id
  77.         mov     byte [edi],3
  78.         inc     edi
  79.         stos    dword [edi]
  80.         xor     al,al
  81.         stos    byte [edi]
  82.         inc     esi
  83.         xor     bx,bx
  84.         call    parse_line_contents
  85.         jmp     parse_next_line
  86.       data_label:
  87.         pop     ecx edx
  88.         pop     edi
  89.         push    eax ebx esi
  90.         mov     esi,edx
  91.         movzx   ecx,byte [esi-1]
  92.         call    identify_label
  93.         mov     byte [edi],2
  94.         inc     edi
  95.         stos    dword [edi]
  96.         pop     esi ebx eax
  97.         stos    byte [edi]
  98.         push    edi
  99.       main_instruction_identified:
  100.         pop     edi
  101.         mov     dl,al
  102.         mov     al,1
  103.         stos    byte [edi]
  104.         mov     ax,bx
  105.         stos    word [edi]
  106.         mov     al,dl
  107.         stos    byte [edi]
  108.         cmp     bx,if_directive-instruction_handler
  109.         je      parse_block
  110.         cmp     bx,repeat_directive-instruction_handler
  111.         je      parse_block
  112.         cmp     bx,while_directive-instruction_handler
  113.         je      parse_block
  114.         cmp     bx,end_directive-instruction_handler
  115.         je      parse_end_directive
  116.         cmp     bx,else_directive-instruction_handler
  117.         je      parse_else
  118.         cmp     bx,assert_directive-instruction_handler
  119.         je      parse_assert
  120.       common_parse:
  121.         call    parse_line_contents
  122.         jmp     parse_next_line
  123.       empty_instruction:
  124.         lods    byte [esi]
  125.         or      al,al
  126.         jz      parse_next_line
  127.         cmp     al,':'
  128.         je      invalid_name
  129.         dec     esi
  130.         cmp     al,3Bh
  131.         je      skip_rest_of_line
  132.         mov     [parenthesis_stack],0
  133.         call    parse_argument
  134.         jmp     parse_next_line
  135.       empty_line:
  136.         add     esi,16
  137.       skip_rest_of_line:
  138.         call    skip_foreign_line
  139.       parse_next_line:
  140.         cmp     esi,[source_start]
  141.         jb      parser_loop
  142.       source_parsed:
  143.         cmp     [blocks_stack],0
  144.         je      blocks_stack_ok
  145.         pop     eax
  146.         pop     [current_line]
  147.         jmp     missing_end_directive
  148.       blocks_stack_ok:
  149.         xor     al,al
  150.         stos    byte [edi]
  151.         add     edi,0Fh
  152.         and     edi,not 0Fh
  153.         mov     [code_start],edi
  154.         ret
  155.       parse_block:
  156.         mov     eax,esp
  157.         sub     eax,100h
  158.         jc      stack_overflow
  159.         cmp     eax,[stack_limit]
  160.         jb      stack_overflow
  161.         push    [current_line]
  162.         mov     ax,bx
  163.         shl     eax,16
  164.         push    eax
  165.         inc     [blocks_stack]
  166.         cmp     bx,if_directive-instruction_handler
  167.         je      parse_if
  168.         cmp     bx,while_directive-instruction_handler
  169.         je      parse_while
  170.         call    parse_line_contents
  171.         jmp     parse_next_line
  172.       parse_end_directive:
  173.         cmp     byte [esi],1Ah
  174.         jne     common_parse
  175.         push    edi
  176.         inc     esi
  177.         movzx   ecx,byte [esi]
  178.         inc     esi
  179.         call    get_instruction
  180.         pop     edi
  181.         jnc     parse_end_block
  182.         sub     esi,2
  183.         jmp     common_parse
  184.       parse_end_block:
  185.         mov     dl,al
  186.         mov     al,1
  187.         stos    byte [edi]
  188.         mov     ax,bx
  189.         stos    word [edi]
  190.         mov     al,dl
  191.         stos    byte [edi]
  192.         lods    byte [esi]
  193.         or      al,al
  194.         jnz     extra_characters_on_line
  195.         cmp     bx,if_directive-instruction_handler
  196.         je      close_parsing_block
  197.         cmp     bx,repeat_directive-instruction_handler
  198.         je      close_parsing_block
  199.         cmp     bx,while_directive-instruction_handler
  200.         je      close_parsing_block
  201.         jmp     parse_next_line
  202.       close_parsing_block:
  203.         cmp     [blocks_stack],0
  204.         je      unexpected_instruction
  205.         cmp     bx,[esp+2]
  206.         jne     unexpected_instruction
  207.         dec     [blocks_stack]
  208.         pop     eax edx
  209.         cmp     bx,if_directive-instruction_handler
  210.         jne     parse_next_line
  211.         test    al,1100b
  212.         jz      parse_next_line
  213.         test    al,10000b
  214.         jnz     parse_next_line
  215.         sub     edi,8
  216.         jmp     parse_next_line
  217.       parse_if:
  218.         push    edi
  219.         call    parse_line_contents
  220.         xor     al,al
  221.         stos    byte [edi]
  222.         xchg    esi,[esp]
  223.         mov     edi,esi
  224.         call    preevaluate_logical_expression
  225.         pop     esi
  226.         cmp     al,'0'
  227.         je      parse_false_condition_block
  228.         cmp     al,'1'
  229.         je      parse_true_condition_block
  230.         or      byte [esp],10000b
  231.         jmp     parse_next_line
  232.       parse_while:
  233.         push    edi
  234.         call    parse_line_contents
  235.         xor     al,al
  236.         stos    byte [edi]
  237.         xchg    esi,[esp]
  238.         mov     edi,esi
  239.         call    preevaluate_logical_expression
  240.         pop     esi
  241.         cmp     al,'0'
  242.         je      parse_false_condition_block
  243.         cmp     al,'1'
  244.         jne     parse_next_line
  245.         stos    byte [edi]
  246.         jmp     parse_next_line
  247.       parse_false_condition_block:
  248.         or      byte [esp],1
  249.         sub     edi,4
  250.         jmp     skip_parsing
  251.       parse_true_condition_block:
  252.         or      byte [esp],100b
  253.         sub     edi,4
  254.         jmp     parse_next_line
  255.       parse_else:
  256.         cmp     [blocks_stack],0
  257.         je      unexpected_instruction
  258.         cmp     word [esp+2],if_directive-instruction_handler
  259.         jne     unexpected_instruction
  260.         lods    byte [esi]
  261.         or      al,al
  262.         jz      parse_pure_else
  263.         cmp     al,1Ah
  264.         jne     extra_characters_on_line
  265.         push    edi
  266.         movzx   ecx,byte [esi]
  267.         inc     esi
  268.         call    get_instruction
  269.         jc      extra_characters_on_line
  270.         pop     edi
  271.         cmp     bx,if_directive-instruction_handler
  272.         jne     extra_characters_on_line
  273.         test    byte [esp],100b
  274.         jnz     skip_true_condition_else
  275.         mov     dl,al
  276.         mov     al,1
  277.         stos    byte [edi]
  278.         mov     ax,bx
  279.         stos    word [edi]
  280.         mov     al,dl
  281.         stos    byte [edi]
  282.         jmp     parse_if
  283.       parse_assert:
  284.         push    edi
  285.         call    parse_line_contents
  286.         xor     al,al
  287.         stos    byte [edi]
  288.         xchg    esi,[esp]
  289.         mov     edi,esi
  290.         call    preevaluate_logical_expression
  291.         pop     esi
  292.         or      al,al
  293.         jz      parse_next_line
  294.         stos    byte [edi]
  295.         jmp     parse_next_line
  296.       skip_true_condition_else:
  297.         sub     edi,4
  298.         or      byte [esp],1
  299.         jmp     skip_parsing_contents
  300.       parse_pure_else:
  301.         bts     dword [esp],1
  302.         jc      unexpected_instruction
  303.         test    byte [esp],100b
  304.         jz      parse_next_line
  305.         sub     edi,4
  306.         or      byte [esp],1
  307.         jmp     skip_parsing
  308.       skip_parsing:
  309.         cmp     esi,[source_start]
  310.         jae     source_parsed
  311.         mov     [current_line],esi
  312.         add     esi,16
  313.       skip_parsing_line:
  314.         cmp     byte [esi],1Ah
  315.         jne     skip_parsing_contents
  316.         inc     esi
  317.         movzx   ecx,byte [esi]
  318.         inc     esi
  319.         cmp     byte [esi+ecx],':'
  320.         je      skip_parsing_label
  321.         push    edi
  322.         call    get_instruction
  323.         pop     edi
  324.         jnc     skip_parsing_instruction
  325.         add     esi,ecx
  326.         jmp     skip_parsing_contents
  327.       skip_parsing_label:
  328.         lea     esi,[esi+ecx+1]
  329.         jmp     skip_parsing_line
  330.       skip_parsing_instruction:
  331.         cmp     bx,if_directive-instruction_handler
  332.         je      skip_parsing_block
  333.         cmp     bx,repeat_directive-instruction_handler
  334.         je      skip_parsing_block
  335.         cmp     bx,while_directive-instruction_handler
  336.         je      skip_parsing_block
  337.         cmp     bx,end_directive-instruction_handler
  338.         je      skip_parsing_end_directive
  339.         cmp     bx,else_directive-instruction_handler
  340.         je      skip_parsing_else
  341.       skip_parsing_contents:
  342.         lods    byte [esi]
  343.         or      al,al
  344.         jz      skip_parsing
  345.         cmp     al,1Ah
  346.         je      skip_parsing_symbol
  347.         cmp     al,3Bh
  348.         je      skip_parsing_symbol
  349.         cmp     al,22h
  350.         je      skip_parsing_string
  351.         jmp     skip_parsing_contents
  352.       skip_parsing_symbol:
  353.         lods    byte [esi]
  354.         movzx   eax,al
  355.         add     esi,eax
  356.         jmp     skip_parsing_contents
  357.       skip_parsing_string:
  358.         lods    dword [esi]
  359.         add     esi,eax
  360.         jmp     skip_parsing_contents
  361.       skip_parsing_block:
  362.         mov     eax,esp
  363.         sub     eax,100h
  364.         jc      stack_overflow
  365.         cmp     eax,[stack_limit]
  366.         jb      stack_overflow
  367.         push    [current_line]
  368.         mov     ax,bx
  369.         shl     eax,16
  370.         push    eax
  371.         inc     [blocks_stack]
  372.         jmp     skip_parsing_contents
  373.       skip_parsing_end_directive:
  374.         cmp     byte [esi],1Ah
  375.         jne     skip_parsing_contents
  376.         push    edi
  377.         inc     esi
  378.         movzx   ecx,byte [esi]
  379.         inc     esi
  380.         call    get_instruction
  381.         pop     edi
  382.         jnc     skip_parsing_end_block
  383.         add     esi,ecx
  384.         jmp     skip_parsing_contents
  385.       skip_parsing_end_block:
  386.         lods    byte [esi]
  387.         or      al,al
  388.         jnz     extra_characters_on_line
  389.         cmp     bx,if_directive-instruction_handler
  390.         je      close_skip_parsing_block
  391.         cmp     bx,repeat_directive-instruction_handler
  392.         je      close_skip_parsing_block
  393.         cmp     bx,while_directive-instruction_handler
  394.         je      close_skip_parsing_block
  395.         jmp     skip_parsing
  396.       close_skip_parsing_block:
  397.         cmp     [blocks_stack],0
  398.         je      unexpected_instruction
  399.         cmp     bx,[esp+2]
  400.         jne     unexpected_instruction
  401.         dec     [blocks_stack]
  402.         pop     eax edx
  403.         test    al,1
  404.         jz      skip_parsing
  405.         cmp     bx,if_directive-instruction_handler
  406.         jne     parse_next_line
  407.         test    al,10000b
  408.         jz      parse_next_line
  409.         mov     al,0Fh
  410.         stos    byte [edi]
  411.         mov     eax,[current_line]
  412.         stos    dword [edi]
  413.         inc     [parsed_lines]
  414.         mov     eax,1 + (end_directive-instruction_handler) shl 8
  415.         stos    dword [edi]
  416.         mov     eax,1 + (if_directive-instruction_handler) shl 8
  417.         stos    dword [edi]
  418.         jmp     parse_next_line
  419.       skip_parsing_else:
  420.         cmp     [blocks_stack],0
  421.         je      unexpected_instruction
  422.         cmp     word [esp+2],if_directive-instruction_handler
  423.         jne     unexpected_instruction
  424.         lods    byte [esi]
  425.         or      al,al
  426.         jz      skip_parsing_pure_else
  427.         cmp     al,1Ah
  428.         jne     extra_characters_on_line
  429.         push    edi
  430.         movzx   ecx,byte [esi]
  431.         inc     esi
  432.         call    get_instruction
  433.         jc      extra_characters_on_line
  434.         pop     edi
  435.         cmp     bx,if_directive-instruction_handler
  436.         jne     extra_characters_on_line
  437.         mov     al,[esp]
  438.         test    al,1
  439.         jz      skip_parsing_contents
  440.         test    al,100b
  441.         jnz     skip_parsing_contents
  442.         test    al,10000b
  443.         jnz     parse_else_if
  444.         xor     al,al
  445.         mov     [esp],al
  446.         mov     al,0Fh
  447.         stos    byte [edi]
  448.         mov     eax,[current_line]
  449.         stos    dword [edi]
  450.         inc     [parsed_lines]
  451.       parse_else_if:
  452.         mov     eax,1 + (if_directive-instruction_handler) shl 8
  453.         stos    dword [edi]
  454.         jmp     parse_if
  455.       skip_parsing_pure_else:
  456.         bts     dword [esp],1
  457.         jc      unexpected_instruction
  458.         mov     al,[esp]
  459.         test    al,1
  460.         jz      skip_parsing
  461.         test    al,100b
  462.         jnz     skip_parsing
  463.         and     al,not 1
  464.         or      al,1000b
  465.         mov     [esp],al
  466.         jmp     parse_next_line
  467.  
  468. parse_line_contents:
  469.         mov     [parenthesis_stack],0
  470.       parse_instruction_arguments:
  471.         cmp     bx,prefix_instruction-instruction_handler
  472.         je      allow_embedded_instruction
  473.         cmp     bx,times_directive-instruction_handler
  474.         je      parse_times_directive
  475.         cmp     bx,end_directive-instruction_handler
  476.         je      allow_embedded_instruction
  477.         cmp     bx,label_directive-instruction_handler
  478.         je      parse_label_directive
  479.         cmp     bx,segment_directive-instruction_handler
  480.         je      parse_segment_directive
  481.         cmp     bx,load_directive-instruction_handler
  482.         je      parse_load_directive
  483.         cmp     bx,extrn_directive-instruction_handler
  484.         je      parse_extrn_directive
  485.         cmp     bx,public_directive-instruction_handler
  486.         je      parse_public_directive
  487.         cmp     bx,section_directive-instruction_handler
  488.         je      parse_formatter_argument
  489.         cmp     bx,format_directive-instruction_handler
  490.         je      parse_formatter_argument
  491.         cmp     bx,data_directive-instruction_handler
  492.         je      parse_formatter_argument
  493.         jmp     parse_argument
  494.       parse_formatter_argument:
  495.         or      [formatter_symbols_allowed],-1
  496.       parse_argument:
  497.         lea     eax,[edi+100h]
  498.         cmp     eax,[labels_list]
  499.         jae     out_of_memory
  500.         lods    byte [esi]
  501.         cmp     al,':'
  502.         je      instruction_separator
  503.         cmp     al,','
  504.         je      separator
  505.         cmp     al,'='
  506.         je      separator
  507.         cmp     al,'|'
  508.         je      separator
  509.         cmp     al,'&'
  510.         je      separator
  511.         cmp     al,'~'
  512.         je      separator
  513.         cmp     al,'>'
  514.         je      greater
  515.         cmp     al,'<'
  516.         je      less
  517.         cmp     al,')'
  518.         je      close_parenthesis
  519.         or      al,al
  520.         jz      contents_parsed
  521.         cmp     al,'['
  522.         je      address_argument
  523.         cmp     al,']'
  524.         je      separator
  525.         cmp     al,'{'
  526.         je      unallowed_character
  527.         cmp     al,'}'
  528.         je      unallowed_character
  529.         cmp     al,'#'
  530.         je      unallowed_character
  531.         cmp     al,'`'
  532.         je      unallowed_character
  533.         dec     esi
  534.         cmp     al,1Ah
  535.         jne     expression_argument
  536.         push    edi
  537.         mov     edi,directive_operators
  538.         call    get_operator
  539.         or      al,al
  540.         jnz     operator_argument
  541.         inc     esi
  542.         movzx   ecx,byte [esi]
  543.         inc     esi
  544.         call    get_symbol
  545.         jnc     symbol_argument
  546.         cmp     ecx,1
  547.         jne     check_argument
  548.         cmp     byte [esi],'?'
  549.         jne     check_argument
  550.         pop     edi
  551.         movs    byte [edi],[esi]
  552.         jmp     argument_parsed
  553.       symbol_argument:
  554.         pop     edi
  555.         stos    word [edi]
  556.         jmp     argument_parsed
  557.       operator_argument:
  558.         pop     edi
  559.         cmp     al,85h
  560.         je      ptr_argument
  561.         stos    byte [edi]
  562.         cmp     al,80h
  563.         je      forced_expression
  564.         cmp     al,8Ch
  565.         je      forced_expression
  566.         cmp     al,81h
  567.         je      forced_parenthesis
  568.         cmp     al,82h
  569.         je      parse_from_operator
  570.         cmp     al,89h
  571.         je      parse_label_operator
  572.         jmp     argument_parsed
  573.       allow_embedded_instruction:
  574.         cmp     byte [esi],1Ah
  575.         jne     parse_argument
  576.         push    edi
  577.         inc     esi
  578.         movzx   ecx,byte [esi]
  579.         inc     esi
  580.         call    get_instruction
  581.         jnc     embedded_instruction
  582.         call    get_data_directive
  583.         jnc     embedded_instruction
  584.         pop     edi
  585.         sub     esi,2
  586.         jmp     parse_argument
  587.       embedded_instruction:
  588.         pop     edi
  589.         mov     dl,al
  590.         mov     al,1
  591.         stos    byte [edi]
  592.         mov     ax,bx
  593.         stos    word [edi]
  594.         mov     al,dl
  595.         stos    byte [edi]
  596.         jmp     parse_instruction_arguments
  597.       parse_times_directive:
  598.         mov     al,'('
  599.         stos    byte [edi]
  600.         call    convert_expression
  601.         mov     al,')'
  602.         stos    byte [edi]
  603.         cmp     byte [esi],':'
  604.         jne     allow_embedded_instruction
  605.         movs    byte [edi],[esi]
  606.         jmp     allow_embedded_instruction
  607.       parse_segment_directive:
  608.         or      [formatter_symbols_allowed],-1
  609.       parse_label_directive:
  610.         cmp     byte [esi],1Ah
  611.         jne     argument_parsed
  612.         push    esi
  613.         inc     esi
  614.         movzx   ecx,byte [esi]
  615.         inc     esi
  616.         call    identify_label
  617.         pop     ebx
  618.         cmp     eax,0Fh
  619.         je      non_label_identified
  620.         mov     byte [edi],2
  621.         inc     edi
  622.         stos    dword [edi]
  623.         xor     al,al
  624.         stos    byte [edi]
  625.         jmp     argument_parsed
  626.       non_label_identified:
  627.         mov     esi,ebx
  628.         jmp     argument_parsed
  629.       parse_load_directive:
  630.         cmp     byte [esi],1Ah
  631.         jne     argument_parsed
  632.         push    esi
  633.         inc     esi
  634.         movzx   ecx,byte [esi]
  635.         inc     esi
  636.         call    get_label_id
  637.         pop     ebx
  638.         cmp     eax,0Fh
  639.         je      non_label_identified
  640.         mov     byte [edi],2
  641.         inc     edi
  642.         stos    dword [edi]
  643.         xor     al,al
  644.         stos    byte [edi]
  645.         jmp     argument_parsed
  646.       parse_public_directive:
  647.         cmp     byte [esi],1Ah
  648.         jne     parse_argument
  649.         inc     esi
  650.         push    esi
  651.         movzx   ecx,byte [esi]
  652.         inc     esi
  653.         push    esi ecx
  654.         push    edi
  655.         or      [formatter_symbols_allowed],-1
  656.         call    get_symbol
  657.         mov     [formatter_symbols_allowed],0
  658.         pop     edi
  659.         jc      parse_public_label
  660.         cmp     al,1Dh
  661.         jne     parse_public_label
  662.         add     esp,12
  663.         stos    word [edi]
  664.         jmp     parse_public_directive
  665.       parse_public_label:
  666.         pop     ecx esi
  667.         mov     al,2
  668.         stos    byte [edi]
  669.         call    get_label_id
  670.         stos    dword [edi]
  671.         mov     ax,8600h
  672.         stos    word [edi]
  673.         pop     ebx
  674.         push    ebx esi edi
  675.         mov     edi,directive_operators
  676.         call    get_operator
  677.         pop     edi edx ebx
  678.         cmp     al,86h
  679.         je      argument_parsed
  680.         mov     esi,edx
  681.         xchg    esi,ebx
  682.         movzx   ecx,byte [esi]
  683.         inc     esi
  684.         mov     ax,'('
  685.         stos    word [edi]
  686.         mov     eax,ecx
  687.         stos    dword [edi]
  688.         rep     movs byte [edi],[esi]
  689.         xor     al,al
  690.         stos    byte [edi]
  691.         xchg    esi,ebx
  692.         jmp     argument_parsed
  693.       parse_extrn_directive:
  694.         cmp     byte [esi],22h
  695.         je      parse_quoted_extrn
  696.         cmp     byte [esi],1Ah
  697.         jne     parse_argument
  698.         push    esi
  699.         movzx   ecx,byte [esi+1]
  700.         add     esi,2
  701.         mov     ax,'('
  702.         stos    word [edi]
  703.         mov     eax,ecx
  704.         stos    dword [edi]
  705.         rep     movs byte [edi],[esi]
  706.         mov     ax,8600h
  707.         stos    word [edi]
  708.         pop     esi
  709.       parse_label_operator:
  710.         cmp     byte [esi],1Ah
  711.         jne     argument_parsed
  712.         inc     esi
  713.         movzx   ecx,byte [esi]
  714.         inc     esi
  715.         mov     al,2
  716.         stos    byte [edi]
  717.         call    get_label_id
  718.         stos    dword [edi]
  719.         xor     al,al
  720.         stos    byte [edi]
  721.         jmp     argument_parsed
  722.       parse_from_operator:
  723.         cmp     byte [esi],22h
  724.         jne     forced_expression
  725.         jmp     argument_parsed
  726.       parse_quoted_extrn:
  727.         inc     esi
  728.         mov     ax,'('
  729.         stos    word [edi]
  730.         lods    dword [esi]
  731.         mov     ecx,eax
  732.         stos    dword [edi]
  733.         rep     movs byte [edi],[esi]
  734.         xor     al,al
  735.         stos    byte [edi]
  736.         push    esi edi
  737.         mov     edi,directive_operators
  738.         call    get_operator
  739.         mov     edx,esi
  740.         pop     edi esi
  741.         cmp     al,86h
  742.         jne     argument_parsed
  743.         stos    byte [edi]
  744.         mov     esi,edx
  745.         jmp     parse_label_operator
  746.       ptr_argument:
  747.         call    parse_address
  748.         jmp     address_parsed
  749.       check_argument:
  750.         push    esi ecx
  751.         sub     esi,2
  752.         mov     edi,single_operand_operators
  753.         call    get_operator
  754.         pop     ecx esi
  755.         or      al,al
  756.         jnz     not_instruction
  757.         call    get_instruction
  758.         jnc     embedded_instruction
  759.         call    get_data_directive
  760.         jnc     embedded_instruction
  761.       not_instruction:
  762.         pop     edi
  763.         sub     esi,2
  764.       expression_argument:
  765.         cmp     byte [esi],22h
  766.         jne     not_string
  767.         mov     eax,[esi+1]
  768.         lea     ebx,[esi+5+eax]
  769.         push    ebx ecx esi edi
  770.         mov     al,'('
  771.         stos    byte [edi]
  772.         call    convert_expression
  773.         mov     al,')'
  774.         stos    byte [edi]
  775.         pop     eax edx ecx ebx
  776.         cmp     esi,ebx
  777.         jne     expression_parsed
  778.         mov     edi,eax
  779.         mov     esi,edx
  780.       string_argument:
  781.         inc     esi
  782.         mov     ax,'('
  783.         stos    word [edi]
  784.         lods    dword [esi]
  785.         mov     ecx,eax
  786.         stos    dword [edi]
  787.         shr     ecx,1
  788.         jnc     string_movsb_ok
  789.         movs    byte [edi],[esi]
  790.       string_movsb_ok:
  791.         shr     ecx,1
  792.         jnc     string_movsw_ok
  793.         movs    word [edi],[esi]
  794.       string_movsw_ok:
  795.         rep     movs dword [edi],[esi]
  796.         xor     al,al
  797.         stos    byte [edi]
  798.         jmp     expression_parsed
  799.       not_string:
  800.         cmp     byte [esi],'('
  801.         jne     expression
  802.         mov     eax,esp
  803.         sub     eax,100h
  804.         jc      stack_overflow
  805.         cmp     eax,[stack_limit]
  806.         jb      stack_overflow
  807.         push    esi edi
  808.         inc     esi
  809.         mov     al,'{'
  810.         stos    byte [edi]
  811.         inc     [parenthesis_stack]
  812.         jmp     parse_argument
  813.       expression:
  814.         mov     al,'('
  815.         stos    byte [edi]
  816.         call    convert_expression
  817.         mov     al,')'
  818.         stos    byte [edi]
  819.         jmp     expression_parsed
  820.       forced_expression:
  821.         xor     al,al
  822.         xchg    al,[formatter_symbols_allowed]
  823.         push    eax
  824.         mov     al,'('
  825.         stos    byte [edi]
  826.         call    convert_expression
  827.         mov     al,')'
  828.         stos    byte [edi]
  829.         pop     eax
  830.         mov     [formatter_symbols_allowed],al
  831.         jmp     argument_parsed
  832.       address_argument:
  833.         call    parse_address
  834.         lods    byte [esi]
  835.         cmp     al,']'
  836.         je      address_parsed
  837.         dec     esi
  838.         mov     al,')'
  839.         stos    byte [edi]
  840.         jmp     argument_parsed
  841.       address_parsed:
  842.         mov     al,']'
  843.         stos    byte [edi]
  844.         jmp     argument_parsed
  845.       parse_address:
  846.         mov     al,'['
  847.         stos    byte [edi]
  848.         cmp     word [esi],021Ah
  849.         jne     convert_address
  850.         push    esi
  851.         add     esi,4
  852.         lea     ebx,[esi+1]
  853.         cmp     byte [esi],':'
  854.         pop     esi
  855.         jne     convert_address
  856.         add     esi,2
  857.         mov     ecx,2
  858.         push    ebx edi
  859.         call    get_symbol
  860.         pop     edi esi
  861.         jc      unknown_segment_prefix
  862.         cmp     al,10h
  863.         jne     unknown_segment_prefix
  864.         mov     al,ah
  865.         and     ah,11110000b
  866.         cmp     ah,60h
  867.         jne     unknown_segment_prefix
  868.         stos    byte [edi]
  869.         jmp     convert_address
  870.       unknown_segment_prefix:
  871.         sub     esi,5
  872.       convert_address:
  873.         push    edi
  874.         mov     edi,address_sizes
  875.         call    get_operator
  876.         pop     edi
  877.         or      al,al
  878.         jz      convert_expression
  879.         add     al,70h
  880.         stos    byte [edi]
  881.         jmp     convert_expression
  882.       forced_parenthesis:
  883.         cmp     byte [esi],'('
  884.         jne     argument_parsed
  885.         inc     esi
  886.         mov     al,'{'
  887.         jmp     separator
  888.       unallowed_character:
  889.         mov     al,0FFh
  890.         jmp     separator
  891.       close_parenthesis:
  892.         mov     al,'}'
  893.       separator:
  894.         stos    byte [edi]
  895.         jmp     argument_parsed
  896.       instruction_separator:
  897.         stos    byte [edi]
  898.         jmp     allow_embedded_instruction
  899.       greater:
  900.         cmp     byte [esi],'='
  901.         jne     separator
  902.         inc     esi
  903.         mov     al,0F2h
  904.         jmp     separator
  905.       less:
  906.         cmp     byte [edi-1],0F6h
  907.         je      separator
  908.         cmp     byte [esi],'>'
  909.         je      not_equal
  910.         cmp     byte [esi],'='
  911.         jne     separator
  912.         inc     esi
  913.         mov     al,0F3h
  914.         jmp     separator
  915.       not_equal:
  916.         inc     esi
  917.         mov     al,0F1h
  918.         jmp     separator
  919.       argument_parsed:
  920.         cmp     [parenthesis_stack],0
  921.         je      parse_argument
  922.         dec     [parenthesis_stack]
  923.         add     esp,8
  924.         jmp     argument_parsed
  925.       expression_parsed:
  926.         cmp     [parenthesis_stack],0
  927.         je      parse_argument
  928.         cmp     byte [esi],')'
  929.         jne     argument_parsed
  930.         dec     [parenthesis_stack]
  931.         pop     edi esi
  932.         jmp     expression
  933.       contents_parsed:
  934.         cmp     [parenthesis_stack],0
  935.         je      contents_ok
  936.         dec     [parenthesis_stack]
  937.         add     esp,8
  938.         jmp     contents_parsed
  939.       contents_ok:
  940.         ret
  941.  
  942. identify_label:
  943.         cmp     byte [esi],'.'
  944.         je      local_label_name
  945.         call    get_label_id
  946.         cmp     eax,10h
  947.         jb      label_identified
  948.         or      ebx,ebx
  949.         jz      anonymous_label_name
  950.         dec     ebx
  951.         mov     [current_locals_prefix],ebx
  952.       label_identified:
  953.         ret
  954.       anonymous_label_name:
  955.         cmp     byte [esi-1],'@'
  956.         je      anonymous_label_name_ok
  957.         mov     eax,0Fh
  958.       anonymous_label_name_ok:
  959.         ret
  960.       local_label_name:
  961.         call    get_label_id
  962.         ret
  963.  
  964. get_operator:
  965.         cmp     byte [esi],1Ah
  966.         jne     get_simple_operator
  967.         mov     edx,esi
  968.         push    ebp
  969.         inc     esi
  970.         lods    byte [esi]
  971.         movzx   ebp,al
  972.         push    edi
  973.         mov     ecx,ebp
  974.         call    lower_case
  975.         pop     edi
  976.       check_operator:
  977.         mov     esi,converted
  978.         movzx   ecx,byte [edi]
  979.         jecxz   no_operator
  980.         inc     edi
  981.         mov     ebx,edi
  982.         add     ebx,ecx
  983.         cmp     ecx,ebp
  984.         jne     next_operator
  985.         repe    cmps byte [esi],[edi]
  986.         je      operator_found
  987.       next_operator:
  988.         mov     edi,ebx
  989.         inc     edi
  990.         jmp     check_operator
  991.       no_operator:
  992.         mov     esi,edx
  993.         mov     ecx,ebp
  994.         pop     ebp
  995.       no_simple_operator:
  996.         xor     al,al
  997.         ret
  998.       operator_found:
  999.         lea     esi,[edx+2+ebp]
  1000.         mov     ecx,ebp
  1001.         pop     ebp
  1002.         mov     al,[edi]
  1003.         ret
  1004.       get_simple_operator:
  1005.         mov     al,[esi]
  1006.         cmp     al,22h
  1007.         je      no_simple_operator
  1008.       simple_operator:
  1009.         cmp     byte [edi],1
  1010.         jb      no_simple_operator
  1011.         ja      simple_next_operator
  1012.         cmp     al,[edi+1]
  1013.         je      simple_operator_found
  1014.       simple_next_operator:
  1015.         movzx   ecx,byte [edi]
  1016.         lea     edi,[edi+1+ecx+1]
  1017.         jmp     simple_operator
  1018.       simple_operator_found:
  1019.         inc     esi
  1020.         mov     al,[edi+2]
  1021.         ret
  1022.  
  1023. get_symbol:
  1024.         push    esi
  1025.         mov     ebp,ecx
  1026.         call    lower_case
  1027.         mov     ecx,ebp
  1028.         cmp     cl,11
  1029.         ja      no_symbol
  1030.         sub     cl,2
  1031.         jc      no_symbol
  1032.         movzx   ebx,word [symbols+ecx*4]
  1033.         add     ebx,symbols
  1034.         movzx   edx,word [symbols+ecx*4+2]
  1035.       scan_symbols:
  1036.         or      edx,edx
  1037.         jz      no_symbol
  1038.         mov     eax,edx
  1039.         shr     eax,1
  1040.         lea     edi,[ebp+2]
  1041.         imul    eax,edi
  1042.         lea     edi,[ebx+eax]
  1043.         mov     esi,converted
  1044.         mov     ecx,ebp
  1045.         repe    cmps byte [esi],[edi]
  1046.         ja      symbols_up
  1047.         jb      symbols_down
  1048.         mov     ax,[edi]
  1049.  
  1050.         cmp     al,18h
  1051.         jb      symbol_ok
  1052.         cmp     [formatter_symbols_allowed],0
  1053.         je      no_symbol
  1054.  
  1055.       symbol_ok:
  1056.         pop     esi
  1057.         add     esi,ebp
  1058.         clc
  1059.         ret
  1060.       no_symbol:
  1061.         pop     esi
  1062.         mov     ecx,ebp
  1063.         stc
  1064.         ret
  1065.       symbols_down:
  1066.         shr     edx,1
  1067.         jmp     scan_symbols
  1068.       symbols_up:
  1069.         lea     ebx,[edi+ecx+2]
  1070.         shr     edx,1
  1071.         adc     edx,-1
  1072.         jmp     scan_symbols
  1073.  
  1074. get_data_directive:
  1075.         push    esi
  1076.         mov     ebp,ecx
  1077.         call    lower_case
  1078.         mov     ecx,ebp
  1079.         cmp     cl,4
  1080.         ja      no_instruction
  1081.         sub     cl,2
  1082.         jc      no_instruction
  1083.         movzx   ebx,word [data_directives+ecx*4]
  1084.         add     ebx,data_directives
  1085.         movzx   edx,word [data_directives+ecx*4+2]
  1086.         jmp     scan_instructions
  1087.  
  1088. get_instruction:
  1089.         push    esi
  1090.         mov     ebp,ecx
  1091.         call    lower_case
  1092.         mov     ecx,ebp
  1093.         cmp     cl,16
  1094.         ja      no_instruction
  1095.         sub     cl,2
  1096.         jc      no_instruction
  1097.         movzx   ebx,word [instructions+ecx*4]
  1098.         add     ebx,instructions
  1099.         movzx   edx,word [instructions+ecx*4+2]
  1100.       scan_instructions:
  1101.         or      edx,edx
  1102.         jz      no_instruction
  1103.         mov     eax,edx
  1104.         shr     eax,1
  1105.         lea     edi,[ebp+3]
  1106.         imul    eax,edi
  1107.         lea     edi,[ebx+eax]
  1108.         mov     esi,converted
  1109.         mov     ecx,ebp
  1110.         repe    cmps byte [esi],[edi]
  1111.         ja      instructions_up
  1112.         jb      instructions_down
  1113.         pop     esi
  1114.         add     esi,ebp
  1115.         mov     al,[edi]
  1116.         mov     bx,[edi+1]
  1117.         clc
  1118.         ret
  1119.       no_instruction:
  1120.         pop     esi
  1121.         mov     ecx,ebp
  1122.         stc
  1123.         ret
  1124.       instructions_down:
  1125.         shr     edx,1
  1126.         jmp     scan_instructions
  1127.       instructions_up:
  1128.         lea     ebx,[edi+ecx+3]
  1129.         shr     edx,1
  1130.         adc     edx,-1
  1131.         jmp     scan_instructions
  1132.  
  1133. get_label_id:
  1134.         cmp     ecx,100h
  1135.         jae     name_too_long
  1136.         cmp     byte [esi],'@'
  1137.         je      anonymous_label
  1138.         cmp     byte [esi],'.'
  1139.         jne     standard_label
  1140.         cmp     byte [esi+1],'.'
  1141.         je      standard_label
  1142.         cmp     [current_locals_prefix],0
  1143.         je      standard_label
  1144.         push    edi
  1145.         mov     edi,[additional_memory_end]
  1146.         sub     edi,2
  1147.         sub     edi,ecx
  1148.         push    ecx esi
  1149.         mov     esi,[current_locals_prefix]
  1150.         lods    byte [esi]
  1151.         movzx   ecx,al
  1152.         sub     edi,ecx
  1153.         cmp     edi,[free_additional_memory]
  1154.         jb      out_of_memory
  1155.         mov     word [edi],0
  1156.         add     edi,2
  1157.         mov     ebx,edi
  1158.         rep     movs byte [edi],[esi]
  1159.         pop     esi ecx
  1160.         add     al,cl
  1161.         jc      name_too_long
  1162.         rep     movs byte [edi],[esi]
  1163.         pop     edi
  1164.         push    ebx esi
  1165.         movzx   ecx,al
  1166.         mov     byte [ebx-1],al
  1167.         mov     esi,ebx
  1168.         call    get_label_id
  1169.         pop     esi ebx
  1170.         cmp     ebx,[eax+24]
  1171.         jne     composed_label_id_ok
  1172.         lea     edx,[ebx-2]
  1173.         mov     [additional_memory_end],edx
  1174.       composed_label_id_ok:
  1175.         ret
  1176.       anonymous_label:
  1177.         cmp     ecx,2
  1178.         jne     standard_label
  1179.         mov     al,[esi+1]
  1180.         mov     ebx,characters
  1181.         xlat    byte [ebx]
  1182.         cmp     al,'@'
  1183.         je      new_anonymous
  1184.         cmp     al,'b'
  1185.         je      anonymous_back
  1186.         cmp     al,'r'
  1187.         je      anonymous_back
  1188.         cmp     al,'f'
  1189.         jne     standard_label
  1190.         add     esi,2
  1191.         mov     eax,[anonymous_forward]
  1192.         or      eax,eax
  1193.         jnz     anonymous_ok
  1194.         mov     eax,[current_line]
  1195.         mov     [error_line],eax
  1196.         call    allocate_label
  1197.         mov     [anonymous_forward],eax
  1198.       anonymous_ok:
  1199.         xor     ebx,ebx
  1200.         ret
  1201.       anonymous_back:
  1202.         mov     eax,[anonymous_reverse]
  1203.         add     esi,2
  1204.         or      eax,eax
  1205.         jz      bogus_anonymous
  1206.         jmp     anonymous_ok
  1207.       bogus_anonymous:
  1208.         call    allocate_label
  1209.         mov     [anonymous_reverse],eax
  1210.         jmp     anonymous_ok
  1211.       new_anonymous:
  1212.         add     esi,2
  1213.         mov     eax,[anonymous_forward]
  1214.         or      eax,eax
  1215.         jnz     new_anonymous_ok
  1216.         call    allocate_label
  1217.       new_anonymous_ok:
  1218.         mov     [anonymous_reverse],eax
  1219.         mov     [anonymous_forward],0
  1220.         jmp     anonymous_ok
  1221.       standard_label:
  1222.         cmp     byte [esi],'%'
  1223.         je      get_predefined_id
  1224.         cmp     byte [esi],'$'
  1225.         je      current_address_label
  1226.         cmp     byte [esi],'?'
  1227.         jne     find_label
  1228.         cmp     ecx,1
  1229.         jne     find_label
  1230.         inc     esi
  1231.         mov     eax,0Fh
  1232.         ret
  1233.       current_address_label:
  1234.         cmp     ecx,2
  1235.         ja      find_label
  1236.         inc     esi
  1237.         jb      get_current_offset_id
  1238.         inc     esi
  1239.         cmp     byte [esi-1],'$'
  1240.         je      get_org_origin_id
  1241.         sub     esi,ecx
  1242.         jmp     find_label
  1243.       get_current_offset_id:
  1244.         xor     eax,eax
  1245.         ret
  1246.       get_counter_id:
  1247.         mov     eax,1
  1248.         ret
  1249.       get_timestamp_id:
  1250.         mov     eax,2
  1251.         ret
  1252.       get_org_origin_id:
  1253.         mov     eax,3
  1254.         ret
  1255.       get_predefined_id:
  1256.         cmp     ecx,2
  1257.         ja      find_label
  1258.         inc     esi
  1259.         cmp     cl,1
  1260.         je      get_counter_id
  1261.         lods    byte [esi]
  1262.         mov     ebx,characters
  1263.         xlat    [ebx]
  1264.         cmp     al,'t'
  1265.         je      get_timestamp_id
  1266.         sub     esi,2
  1267.       find_label:
  1268.         xor     ebx,ebx
  1269.         mov     eax,2166136261
  1270.         mov     ebp,16777619
  1271.       hash_label:
  1272.         xor     al,[esi+ebx]
  1273.         mul     ebp
  1274.         inc     bl
  1275.         cmp     bl,cl
  1276.         jb      hash_label
  1277.         mov     ebp,eax
  1278.         shl     eax,8
  1279.         and     ebp,0FFh shl 24
  1280.         xor     ebp,eax
  1281.         or      ebp,ebx
  1282.         mov     [label_hash],ebp
  1283.         push    edi esi
  1284.         push    ecx
  1285.         mov     ecx,32
  1286.         mov     ebx,hash_tree
  1287.       follow_tree:
  1288.         mov     edx,[ebx]
  1289.         or      edx,edx
  1290.         jz      extend_tree
  1291.         xor     eax,eax
  1292.         shl     ebp,1
  1293.         adc     eax,0
  1294.         lea     ebx,[edx+eax*4]
  1295.         dec     ecx
  1296.         jnz     follow_tree
  1297.         mov     [label_leaf],ebx
  1298.         pop     edx
  1299.         mov     eax,[ebx]
  1300.         or      eax,eax
  1301.         jz      add_label
  1302.         mov     ebx,esi
  1303.         mov     ebp,[label_hash]
  1304.       compare_labels:
  1305.         mov     esi,ebx
  1306.         mov     ecx,edx
  1307.         mov     edi,[eax+4]
  1308.         mov     edi,[edi+24]
  1309.         repe    cmps byte [esi],[edi]
  1310.         je      label_found
  1311.         mov     eax,[eax]
  1312.         or      eax,eax
  1313.         jnz     compare_labels
  1314.         jmp     add_label
  1315.       label_found:
  1316.         add     esp,4
  1317.         pop     edi
  1318.         mov     eax,[eax+4]
  1319.         ret
  1320.       extend_tree:
  1321.         mov     edx,[free_additional_memory]
  1322.         lea     eax,[edx+8]
  1323.         cmp     eax,[additional_memory_end]
  1324.         ja      out_of_memory
  1325.         mov     [free_additional_memory],eax
  1326.         xor     eax,eax
  1327.         mov     [edx],eax
  1328.         mov     [edx+4],eax
  1329.         shl     ebp,1
  1330.         adc     eax,0
  1331.         mov     [ebx],edx
  1332.         lea     ebx,[edx+eax*4]
  1333.         dec     ecx
  1334.         jnz     extend_tree
  1335.         mov     [label_leaf],ebx
  1336.         pop     edx
  1337.       add_label:
  1338.         mov     ecx,edx
  1339.         pop     esi
  1340.         cmp     byte [esi-2],0
  1341.         je      label_name_ok
  1342.         mov     al,[esi]
  1343.         cmp     al,30h
  1344.         jb      name_first_char_ok
  1345.         cmp     al,39h
  1346.         jbe     invalid_name
  1347.       name_first_char_ok:
  1348.         cmp     al,'$'
  1349.         jne     check_for_reserved_word
  1350.         cmp     ecx,1
  1351.         jne     invalid_name
  1352.       reserved_word:
  1353.         mov     eax,0Fh
  1354.         pop     edi
  1355.         ret
  1356.       check_for_reserved_word:
  1357.         call    get_instruction
  1358.         jnc     reserved_word
  1359.         call    get_data_directive
  1360.         jnc     reserved_word
  1361.         call    get_symbol
  1362.         jnc     reserved_word
  1363.         sub     esi,2
  1364.         mov     edi,operators
  1365.         call    get_operator
  1366.         or      al,al
  1367.         jnz     reserved_word
  1368.         mov     edi,single_operand_operators
  1369.         call    get_operator
  1370.         or      al,al
  1371.         jnz     reserved_word
  1372.         mov     edi,directive_operators
  1373.         call    get_operator
  1374.         or      al,al
  1375.         jnz     reserved_word
  1376.         inc     esi
  1377.         movzx   ecx,byte [esi]
  1378.         inc     esi
  1379.       label_name_ok:
  1380.         mov     edx,[free_additional_memory]
  1381.         lea     eax,[edx+8]
  1382.         cmp     eax,[additional_memory_end]
  1383.         ja      out_of_memory
  1384.         mov     [free_additional_memory],eax
  1385.         mov     ebx,esi
  1386.         add     esi,ecx
  1387.         mov     eax,[label_leaf]
  1388.         mov     edi,[eax]
  1389.         mov     [edx],edi
  1390.         mov     [eax],edx
  1391.         call    allocate_label
  1392.         mov     [edx+4],eax
  1393.         mov     [eax+24],ebx
  1394.         pop     edi
  1395.         ret
  1396.       allocate_label:
  1397.         mov     eax,[labels_list]
  1398.         mov     ecx,LABEL_STRUCTURE_SIZE shr 2
  1399.       initialize_label:
  1400.         sub     eax,4
  1401.         mov     dword [eax],0
  1402.         loop    initialize_label
  1403.         mov     [labels_list],eax
  1404.         ret
  1405.  
  1406. LABEL_STRUCTURE_SIZE = 32
  1407.