Subversion Repositories Kolibri OS

Rev

Rev 157 | Blame | Last modification | View Log | Download | RSS feed

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