Subversion Repositories Kolibri OS

Rev

Rev 174 | 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. assembler:
  7.         xor     eax,eax
  8.         mov     [stub_size],eax
  9.         mov     [number_of_sections],eax
  10.         mov     [current_pass],ax
  11.         mov     [resolver_flags],eax
  12.       assembler_loop:
  13.         mov     eax,[labels_list]
  14.         mov     [display_buffer],eax
  15.         mov     eax,[additional_memory]
  16.         mov     [free_additional_memory],eax
  17.         mov     eax,[additional_memory_end]
  18.         mov     [structures_buffer],eax
  19.         mov     esi,[source_start]
  20.         mov     edi,[code_start]
  21.         xor     eax,eax
  22.         mov     dword [adjustment],eax
  23.         mov     dword [adjustment+4],eax
  24.         mov     dword [org_origin],edi
  25.         mov     dword [org_origin+4],eax
  26.         mov     [org_start],edi
  27.         mov     [org_registers],eax
  28.         mov     [org_symbol],eax
  29.         mov     [error_line],eax
  30.         mov     [counter],eax
  31.         mov     [format_flags],eax
  32.         mov     [number_of_relocations],eax
  33.         mov     [undefined_data_end],eax
  34.         mov     [next_pass_needed],al
  35.         mov     [output_format],al
  36.         mov     [labels_type],al
  37.         mov     [virtual_data],al
  38.         mov     [code_type],16
  39.       pass_loop:
  40.         call    assemble_line
  41.         jnc     pass_loop
  42.         mov     eax,[additional_memory_end]
  43.         cmp     eax,[structures_buffer]
  44.         je      pass_done
  45.         sub     eax,20h
  46.         mov     eax,[eax+4]
  47.         mov     [current_line],eax
  48.         jmp     missing_end_directive
  49.       pass_done:
  50.         call    close_pass
  51.         mov     eax,[labels_list]
  52.       check_symbols:
  53.         cmp     eax,[memory_end]
  54.         jae     symbols_checked
  55.         test    byte [eax+8],8
  56.         jz      symbol_defined_ok
  57.         mov     cx,[current_pass]
  58.         cmp     cx,[eax+18]
  59.         jne     symbol_defined_ok
  60.         test    byte [eax+8],1
  61.         jz      symbol_defined_ok
  62.         sub     cx,[eax+16]
  63.         cmp     cx,1
  64.         jne     symbol_defined_ok
  65.         and     byte [eax+8],not 1
  66.         or      [next_pass_needed],-1
  67.       symbol_defined_ok:
  68.         test    byte [eax+8],10h
  69.         jz      use_prediction_ok
  70.         mov     cx,[current_pass]
  71.         and     byte [eax+8],not 10h
  72.         test    byte [eax+8],20h
  73.         jnz     check_use_prediction
  74.         cmp     cx,[eax+18]
  75.         jne     use_prediction_ok
  76.         test    byte [eax+8],8
  77.         jz      use_prediction_ok
  78.         jmp     use_misprediction
  79.       check_use_prediction:
  80.         test    byte [eax+8],8
  81.         jz      use_misprediction
  82.         cmp     cx,[eax+18]
  83.         je      use_prediction_ok
  84.       use_misprediction:
  85.         or      [next_pass_needed],-1
  86.       use_prediction_ok:
  87.         test    byte [eax+8],40h
  88.         jz      check_next_symbol
  89.         and     byte [eax+8],not 40h
  90.         test    byte [eax+8],4
  91.         jnz     define_misprediction
  92.         mov     cx,[current_pass]
  93.         test    byte [eax+8],80h
  94.         jnz     check_define_prediction
  95.         cmp     cx,[eax+16]
  96.         jne     check_next_symbol
  97.         test    byte [eax+8],1
  98.         jz      check_next_symbol
  99.         jmp     define_misprediction
  100.       check_define_prediction:
  101.         test    byte [eax+8],1
  102.         jz      define_misprediction
  103.         cmp     cx,[eax+16]
  104.         je      check_next_symbol
  105.       define_misprediction:
  106.         or      [next_pass_needed],-1
  107.       check_next_symbol:
  108.         add     eax,LABEL_STRUCTURE_SIZE
  109.         jmp     check_symbols
  110.       symbols_checked:
  111.         cmp     [next_pass_needed],0
  112.         jne     next_pass
  113.         mov     eax,[error_line]
  114.         or      eax,eax
  115.         jz      assemble_ok
  116.         mov     [current_line],eax
  117.         jmp     near [error]
  118.       next_pass:
  119.         inc     [current_pass]
  120.         mov     ax,[current_pass]
  121.         cmp     ax,[passes_limit]
  122.         je      code_cannot_be_generated
  123.         jmp     assembler_loop
  124.       assemble_ok:
  125.         ret
  126.  
  127. assemble_line:
  128.         mov     eax,[display_buffer]
  129.         sub     eax,100h
  130.         cmp     edi,eax
  131.         ja      out_of_memory
  132.         lods    byte [esi]
  133.         cmp     al,1
  134.         je      assemble_instruction
  135.         jb      source_end
  136.         cmp     al,3
  137.         jb      define_label
  138.         je      define_constant
  139.         cmp     al,0Fh
  140.         je      new_line
  141.         cmp     al,13h
  142.         je      code_type_setting
  143.         cmp     al,10h
  144.         jne     illegal_instruction
  145.         lods    byte [esi]
  146.         jmp     segment_prefix
  147.       code_type_setting:
  148.         lods    byte [esi]
  149.         mov     [code_type],al
  150.         jmp     line_assembled
  151.       new_line:
  152.         lods    dword [esi]
  153.         mov     [current_line],eax
  154.         mov     [prefixed_instruction],0
  155.       continue_line:
  156.         cmp     byte [esi],0Fh
  157.         je      line_assembled
  158.         jmp     assemble_line
  159.       define_label:
  160.         lods    dword [esi]
  161.         cmp     eax,0Fh
  162.         jb      invalid_use_of_symbol
  163.         je      reserved_word_used_as_symbol
  164.         mov     ebx,eax
  165.         lods    byte [esi]
  166.         mov     cl,al
  167.         mov     eax,edi
  168.         xor     edx,edx
  169.         sub     eax,dword [org_origin]
  170.         sbb     edx,dword [org_origin+4]
  171.         mov     ch,[labels_type]
  172.         cmp     [virtual_data],0
  173.         jne     make_virtual_label
  174.         or      byte [ebx+9],1
  175.         xchg    eax,[ebx]
  176.         xchg    edx,[ebx+4]
  177.         sub     eax,[ebx]
  178.         sbb     edx,[ebx+4]
  179.         mov     dword [adjustment],eax
  180.         mov     dword [adjustment+4],edx
  181.         or      eax,edx
  182.         setnz   ah
  183.         jmp     finish_label_symbol
  184.       make_virtual_label:
  185.         and     byte [ebx+9],not 1
  186.         cmp     eax,[ebx]
  187.         mov     [ebx],eax
  188.         setne   ah
  189.         cmp     edx,[ebx+4]
  190.         mov     [ebx+4],edx
  191.         setne   al
  192.         or      ah,al
  193.       finish_label_symbol:
  194.         cmp     cl,[ebx+10]
  195.         mov     [ebx+10],cl
  196.         setne   al
  197.         or      ah,al
  198.         cmp     ch,[ebx+11]
  199.         mov     [ebx+11],ch
  200.         setne   al
  201.         or      ah,al
  202.         mov     edx,[org_registers]
  203.         cmp     edx,[ebx+12]
  204.         mov     [ebx+12],edx
  205.         setne   al
  206.         or      ah,al
  207.         or      ch,ch
  208.         jz      label_symbol_ok
  209.         mov     edx,[org_symbol]
  210.         cmp     edx,[ebx+20]
  211.         mov     [ebx+20],edx
  212.         setne   al
  213.         or      ah,al
  214.       label_symbol_ok:
  215.         mov     cx,[current_pass]
  216.         xchg    [ebx+16],cx
  217.         mov     edx,[current_line]
  218.         mov     [ebx+28],edx
  219.         and     byte [ebx+8],not 2
  220.         test    byte [ebx+8],1
  221.         jz      new_label
  222.         cmp     cx,[ebx+16]
  223.         je      symbol_already_defined
  224.         inc     cx
  225.         sub     cx,[ebx+16]
  226.         setnz   al
  227.         or      ah,al
  228.         jz      continue_line
  229.         test    byte [ebx+8],8
  230.         jz      continue_line
  231.         mov     cx,[current_pass]
  232.         cmp     cx,[ebx+18]
  233.         jne     continue_line
  234.         or      [next_pass_needed],-1
  235.         jmp     continue_line
  236.       new_label:
  237.         or      byte [ebx+8],1
  238.         jmp     continue_line
  239.       define_constant:
  240.         lods    dword [esi]
  241.         inc     esi
  242.         cmp     eax,0Fh
  243.         jb      invalid_use_of_symbol
  244.         je      reserved_word_used_as_symbol
  245.         mov     edx,[eax+8]
  246.         push    edx
  247.         cmp     [current_pass],0
  248.         je      get_constant_value
  249.         test    dl,4
  250.         jnz     get_constant_value
  251.         mov     cx,[current_pass]
  252.         cmp     cx,[eax+16]
  253.         je      get_constant_value
  254.         and     dl,not 1
  255.         mov     [eax+8],dl
  256.       get_constant_value:
  257.         push    eax
  258.         mov     al,byte [esi-1]
  259.         push    eax
  260.         call    get_value
  261.         pop     ebx
  262.         mov     ch,bl
  263.         pop     ebx
  264.         pop     dword [ebx+8]
  265.         cmp     ebx,0Fh
  266.         jb      invalid_use_of_symbol
  267.         je      reserved_word_used_as_symbol
  268.         xor     cl,cl
  269.         mov     ch,[value_type]
  270.         cmp     ch,3
  271.         je      invalid_use_of_symbol
  272.       make_constant:
  273.         and     byte [ebx+9],not 1
  274.         cmp     eax,[ebx]
  275.         mov     [ebx],eax
  276.         setne   ah
  277.         cmp     edx,[ebx+4]
  278.         mov     [ebx+4],edx
  279.         setne   al
  280.         or      ah,al
  281.         cmp     cl,[ebx+10]
  282.         mov     [ebx+10],cl
  283.         setne   al
  284.         or      ah,al
  285.         cmp     ch,[ebx+11]
  286.         mov     [ebx+11],ch
  287.         setne   al
  288.         or      ah,al
  289.         xor     edx,edx
  290.         cmp     edx,[ebx+12]
  291.         mov     [ebx+12],edx
  292.         setne   al
  293.         or      ah,al
  294.         or      ch,ch
  295.         jz      constant_symbol_ok
  296.         mov     edx,[symbol_identifier]
  297.         cmp     edx,[ebx+20]
  298.         mov     [ebx+20],edx
  299.         setne   al
  300.         or      ah,al
  301.       constant_symbol_ok:
  302.         mov     cx,[current_pass]
  303.         xchg    [ebx+16],cx
  304.         mov     edx,[current_line]
  305.         mov     [ebx+28],edx
  306.         test    byte [ebx+8],1
  307.         jz      new_constant
  308.         cmp     cx,[ebx+16]
  309.         jne     redeclare_constant
  310.         test    byte [ebx+8],2
  311.         jz      symbol_already_defined
  312.         or      byte [ebx+8],4
  313.         jmp     instruction_assembled
  314.       redeclare_constant:
  315.         inc     cx
  316.         sub     cx,[ebx+16]
  317.         setnz   al
  318.         or      ah,al
  319.         jz      instruction_assembled
  320.         test    byte [ebx+8],4
  321.         jnz     instruction_assembled
  322.         test    byte [ebx+8],8
  323.         jz      instruction_assembled
  324.         mov     cx,[current_pass]
  325.         cmp     cx,[ebx+18]
  326.         jne     instruction_assembled
  327.         or      [next_pass_needed],-1
  328.         jmp     instruction_assembled
  329.       new_constant:
  330.         or      byte [ebx+8],1+2
  331.         jmp     instruction_assembled
  332.       assemble_instruction:
  333.         mov     [operand_size],0
  334.         mov     [size_override],0
  335.         mov     [operand_prefix],0
  336.         mov     [rex_prefix],0
  337.         mov     [immediate_size],0
  338.         movzx   ebx,word [esi]
  339.         mov     al,[esi+2]
  340.         add     ebx,assembler
  341.         add     esi,3
  342.         jmp     near ebx
  343.       instruction_assembled:
  344.         mov     al,[esi]
  345.         cmp     al,0Fh
  346.         je      line_assembled
  347.         or      al,al
  348.         jnz     extra_characters_on_line
  349.       line_assembled:
  350.         clc
  351.         ret
  352.       source_end:
  353.         dec     esi
  354.         stc
  355.         ret
  356. skip_line:
  357.         call    skip_symbol
  358.         jnc     skip_line
  359.         ret
  360. skip_symbol:
  361.         lods    byte [esi]
  362.         or      al,al
  363.         jz      nothing_to_skip
  364.         cmp     al,0Fh
  365.         je      nothing_to_skip
  366.         cmp     al,1
  367.         je      skip_instruction
  368.         cmp     al,2
  369.         je      skip_label
  370.         cmp     al,3
  371.         je      skip_label
  372.         cmp     al,20h
  373.         jb      skip_assembler_symbol
  374.         cmp     al,'('
  375.         je      skip_expression
  376.         cmp     al,'['
  377.         je      skip_address
  378.       skip_done:
  379.         clc
  380.         ret
  381.       skip_label:
  382.         add     esi,2
  383.       skip_instruction:
  384.         add     esi,2
  385.       skip_assembler_symbol:
  386.         inc     esi
  387.         jmp     skip_done
  388.       skip_address:
  389.         mov     al,[esi]
  390.         and     al,11110000b
  391.         cmp     al,60h
  392.         jb      skip_expression
  393.         cmp     al,70h
  394.         ja      skip_expression
  395.         inc     esi
  396.         jmp     skip_address
  397.       skip_expression:
  398.         lods    byte [esi]
  399.         or      al,al
  400.         jz      skip_string
  401.         cmp     al,'.'
  402.         je      skip_fp_value
  403.         cmp     al,')'
  404.         je      skip_done
  405.         cmp     al,']'
  406.         je      skip_done
  407.         cmp     al,'!'
  408.         je      skip_expression
  409.         cmp     al,0Fh
  410.         je      skip_expression
  411.         cmp     al,10h
  412.         je      skip_register
  413.         cmp     al,11h
  414.         je      skip_label_value
  415.         cmp     al,80h
  416.         jae     skip_expression
  417.         movzx   eax,al
  418.         add     esi,eax
  419.         jmp     skip_expression
  420.       skip_label_value:
  421.         add     esi,3
  422.       skip_register:
  423.         inc     esi
  424.         jmp     skip_expression
  425.       skip_fp_value:
  426.         add     esi,12
  427.         jmp     skip_done
  428.       skip_string:
  429.         lods    dword [esi]
  430.         add     esi,eax
  431.         inc     esi
  432.         jmp     skip_done
  433.       nothing_to_skip:
  434.         dec     esi
  435.         stc
  436.         ret
  437.  
  438. org_directive:
  439.         lods    byte [esi]
  440.         cmp     al,'('
  441.         jne     invalid_argument
  442.         cmp     byte [esi],'.'
  443.         je      invalid_value
  444.         call    get_qword_value
  445.         mov     cl,[value_type]
  446.         test    cl,1
  447.         jnz     invalid_use_of_symbol
  448.         mov     [labels_type],cl
  449.         mov     ecx,edi
  450.         sub     ecx,eax
  451.         adc     edx,0
  452.         neg     edx
  453.         mov     dword [org_origin],ecx
  454.         mov     dword [org_origin+4],edx
  455.         mov     [org_registers],0
  456.         mov     [org_start],edi
  457.         mov     edx,[symbol_identifier]
  458.         mov     [org_symbol],edx
  459.         cmp     [output_format],1
  460.         ja      instruction_assembled
  461.         cmp     edi,[code_start]
  462.         jne     instruction_assembled
  463.         cmp     eax,100h
  464.         jne     instruction_assembled
  465.         bts     [format_flags],0
  466.         jmp     instruction_assembled
  467. label_directive:
  468.         lods    byte [esi]
  469.         cmp     al,2
  470.         jne     invalid_argument
  471.         lods    dword [esi]
  472.         cmp     eax,0Fh
  473.         jb      invalid_use_of_symbol
  474.         je      reserved_word_used_as_symbol
  475.         inc     esi
  476.         mov     ebx,eax
  477.         xor     cl,cl
  478.         lods    byte [esi]
  479.         cmp     al,':'
  480.         je      get_label_size
  481.         dec     esi
  482.         cmp     al,11h
  483.         jne     label_size_ok
  484.       get_label_size:
  485.         lods    word [esi]
  486.         cmp     al,11h
  487.         jne     invalid_argument
  488.         mov     cl,ah
  489.       label_size_ok:
  490.         mov     eax,edi
  491.         xor     edx,edx
  492.         sub     eax,dword [org_origin]
  493.         sbb     edx,dword [org_origin+4]
  494.         mov     ebp,[org_registers]
  495.         cmp     byte [esi],80h
  496.         je      get_free_label_value
  497.         mov     ch,[labels_type]
  498.         push    [org_symbol]
  499.         pop     [address_symbol]
  500.         cmp     [virtual_data],0
  501.         jne     make_free_label
  502.         or      byte [ebx+9],1
  503.         xchg    eax,[ebx]
  504.         xchg    edx,[ebx+4]
  505.         sub     eax,[ebx]
  506.         sbb     edx,[ebx+4]
  507.         mov     dword [adjustment],eax
  508.         mov     dword [adjustment+4],edx
  509.         or      eax,edx
  510.         setne   ah
  511.         jmp     finish_label
  512.       get_free_label_value:
  513.         inc     esi
  514.         lods    byte [esi]
  515.         cmp     al,'('
  516.         jne     invalid_argument
  517.         push    dword [ebx+8]
  518.         push    ebx ecx
  519.         and     byte [ebx+8],not 1
  520.         cmp     byte [esi],'.'
  521.         je      invalid_value
  522.         call    get_address_value
  523.         or      bh,bh
  524.         setnz   ch
  525.         xchg    ch,cl
  526.         mov     bp,cx
  527.         shl     ebp,16
  528.         xchg    bl,bh
  529.         mov     bp,bx
  530.         pop     ecx ebx
  531.         pop     dword [ebx+8]
  532.         mov     ch,[value_type]
  533.         or      ch,ch
  534.         jz      make_free_label
  535.         cmp     ch,4
  536.         je      make_free_label
  537.         cmp     ch,2
  538.         jne     invalid_use_of_symbol
  539.       make_free_label:
  540.         and     byte [ebx+9],not 1
  541.         cmp     eax,[ebx]
  542.         mov     [ebx],eax
  543.         setne   ah
  544.         cmp     edx,[ebx+4]
  545.         mov     [ebx+4],edx
  546.         setne   al
  547.         or      ah,al
  548.         jmp     finish_label
  549.       finish_label:
  550.         cmp     cl,[ebx+10]
  551.         mov     [ebx+10],cl
  552.         setne   al
  553.         or      ah,al
  554.         cmp     ch,[ebx+11]
  555.         mov     [ebx+11],ch
  556.         setne   al
  557.         or      ah,al
  558.         cmp     ebp,[ebx+12]
  559.         mov     [ebx+12],ebp
  560.         setne   al
  561.         or      ah,al
  562.         or      ch,ch
  563.         jz      free_label_symbol_ok
  564.         mov     edx,[address_symbol]
  565.         cmp     edx,[ebx+20]
  566.         mov     [ebx+20],edx
  567.         setne   al
  568.         or      ah,al
  569.       free_label_symbol_ok:
  570.         mov     cx,[current_pass]
  571.         xchg    [ebx+16],cx
  572.         mov     edx,[current_line]
  573.         mov     [ebx+28],edx
  574.         and     byte [ebx+8],not 2
  575.         test    byte [ebx+8],1
  576.         jz      new_free_label
  577.         cmp     cx,[ebx+16]
  578.         je      symbol_already_defined
  579.         inc     cx
  580.         sub     cx,[ebx+16]
  581.         setnz   al
  582.         or      ah,al
  583.         jz      instruction_assembled
  584.         test    byte [ebx+8],8
  585.         jz      instruction_assembled
  586.         mov     cx,[current_pass]
  587.         cmp     cx,[ebx+18]
  588.         jne     instruction_assembled
  589.         or      [next_pass_needed],-1
  590.         jmp     instruction_assembled
  591.       new_free_label:
  592.         or      byte [ebx+8],1
  593.         jmp     instruction_assembled
  594. load_directive:
  595.         lods    byte [esi]
  596.         cmp     al,2
  597.         jne     invalid_argument
  598.         lods    dword [esi]
  599.         cmp     eax,0Fh
  600.         jb      invalid_use_of_symbol
  601.         je      reserved_word_used_as_symbol
  602.         inc     esi
  603.         push    eax
  604.         mov     al,1
  605.         cmp     byte [esi],11h
  606.         jne     load_size_ok
  607.         lods    byte [esi]
  608.         lods    byte [esi]
  609.       load_size_ok:
  610.         cmp     al,8
  611.         ja      invalid_value
  612.         mov     [operand_size],al
  613.         mov     dword [value],0
  614.         mov     dword [value+4],0
  615.         lods    word [esi]
  616.         cmp     ax,82h+'(' shl 8
  617.         jne     invalid_argument
  618.       load_from_code:
  619.         cmp     byte [esi],'.'
  620.         je      invalid_value
  621.         call    get_address_value
  622.         call    calculate_relative_offset
  623.         push    esi edi
  624.         cmp     [next_pass_needed],0
  625.         jne     load_address_type_ok
  626.         cmp     [value_type],0
  627.         jne     invalid_use_of_symbol
  628.       load_address_type_ok:
  629.         cmp     edx,-1
  630.         jne     bad_load_address
  631.         neg     eax
  632.         mov     esi,edi
  633.         sub     esi,eax
  634.         jc      bad_load_address
  635.         cmp     esi,[org_start]
  636.         jb      bad_load_address
  637.         mov     edi,value
  638.         movzx   ecx,[operand_size]
  639.         cmp     ecx,eax
  640.         ja      bad_load_address
  641.         rep     movs byte [edi],[esi]
  642.         jmp     value_loaded
  643.       bad_load_address:
  644.         cmp     [error_line],0
  645.         jne     value_loaded
  646.         mov     eax,[current_line]
  647.         mov     [error_line],eax
  648.         mov     [error],value_out_of_range
  649.       value_loaded:
  650.         pop     edi esi
  651.         mov     eax,dword [value]
  652.         mov     edx,dword [value+4]
  653.         pop     ebx
  654.         xor     cx,cx
  655.         jmp     make_constant
  656. store_directive:
  657.         cmp     byte [esi],11h
  658.         je      sized_store
  659.         lods    byte [esi]
  660.         cmp     al,'('
  661.         jne     invalid_argument
  662.         call    get_byte_value
  663.         xor     edx,edx
  664.         movzx   eax,al
  665.         mov     [operand_size],1
  666.         jmp     store_value_ok
  667.       sized_store:
  668.         call    get_value
  669.       store_value_ok:
  670.         cmp     [value_type],0
  671.         jne     invalid_use_of_symbol
  672.         mov     dword [value],eax
  673.         mov     dword [value+4],edx
  674.         lods    word [esi]
  675.         cmp     ax,80h+'(' shl 8
  676.         jne     invalid_argument
  677.         cmp     byte [esi],'.'
  678.         je      invalid_value
  679.         call    get_address_value
  680.         call    calculate_relative_offset
  681.         push    esi edi
  682.         cmp     [next_pass_needed],0
  683.         jne     store_address_type_ok
  684.         cmp     [value_type],0
  685.         jne     invalid_use_of_symbol
  686.       store_address_type_ok:
  687.         cmp     edx,-1
  688.         jne     bad_store_address
  689.         neg     eax
  690.         sub     edi,eax
  691.         jc      bad_store_address
  692.         cmp     edi,[org_start]
  693.         jb      bad_store_address
  694.         mov     esi,value
  695.         movzx   ecx,[operand_size]
  696.         cmp     ecx,eax
  697.         ja      bad_store_address
  698.         rep     movs byte [edi],[esi]
  699.         mov     eax,edi
  700.         pop     edi esi
  701.         cmp     edi,[undefined_data_end]
  702.         jne     instruction_assembled
  703.         cmp     eax,[undefined_data_start]
  704.         jbe     instruction_assembled
  705.         mov     [undefined_data_start],eax
  706.         jmp     instruction_assembled
  707.       bad_store_address:
  708.         pop     edi esi
  709.         cmp     [error_line],0
  710.         jne     instruction_assembled
  711.         mov     eax,[current_line]
  712.         mov     [error_line],eax
  713.         mov     [error],value_out_of_range
  714.         jmp     instruction_assembled
  715.  
  716. display_directive:
  717.         lods    byte [esi]
  718.         cmp     al,'('
  719.         jne     invalid_argument
  720.         cmp     byte [esi],0
  721.         jne     display_byte
  722.         inc     esi
  723.         lods    dword [esi]
  724.         mov     ecx,eax
  725.         push    edi
  726.         mov     edi,[display_buffer]
  727.         sub     edi,4
  728.         sub     edi,eax
  729.         mov     [display_buffer],edi
  730.         rep     movs byte [edi],[esi]
  731.         stos    dword [edi]
  732.         pop     edi
  733.         inc     esi
  734.         jmp     display_next
  735.       display_byte:
  736.         call    get_byte_value
  737.         push    edi
  738.         mov     edi,[display_buffer]
  739.         sub     edi,4+1
  740.         mov     [display_buffer],edi
  741.         stos    byte [edi]
  742.         mov     eax,1
  743.         stos    dword [edi]
  744.         pop     edi
  745.       display_next:
  746.         cmp     edi,[display_buffer]
  747.         ja      out_of_memory
  748.         lods    byte [esi]
  749.         cmp     al,','
  750.         je      display_directive
  751.         dec     esi
  752.         jmp     instruction_assembled
  753. flush_display_buffer:
  754.         mov     eax,[display_buffer]
  755.         or      eax,eax
  756.         jz      display_done
  757.         mov     esi,[labels_list]
  758.         cmp     esi,eax
  759.         je      display_done
  760.       display_messages:
  761.         sub     esi,4
  762.         mov     ecx,[esi]
  763.         sub     esi,ecx
  764.         push    esi
  765.         call    display_block
  766.         pop     esi
  767.         cmp     esi,[display_buffer]
  768.         jne     display_messages
  769.         mov     eax,[labels_list]
  770.         mov     [display_buffer],eax
  771.       display_done:
  772.         ret
  773. times_directive:
  774.         lods    byte [esi]
  775.         cmp     al,'('
  776.         jne     invalid_argument
  777.         cmp     byte [esi],'.'
  778.         je      invalid_value
  779.         call    get_dword_value
  780.         cmp     [next_pass_needed],0
  781.         jne     times_value_ok
  782.         cmp     [value_type],0
  783.         jne     invalid_use_of_symbol
  784.       times_value_ok:
  785.         cmp     eax,0
  786.         je      zero_times
  787.         jl      negative_times
  788.         cmp     byte [esi],':'
  789.         jne     times_argument_ok
  790.         inc     esi
  791.       times_argument_ok:
  792.         push    [counter]
  793.         push    [counter_limit]
  794.         mov     [counter_limit],eax
  795.         mov     [counter],1
  796.       times_loop:
  797.         mov     eax,esp
  798.         sub     eax,100h
  799.         jc      stack_overflow
  800.         cmp     eax,[stack_limit]
  801.         jb      stack_overflow
  802.         push    esi
  803.         or      [prefixed_instruction],-1
  804.         call    continue_line
  805.         mov     eax,[counter_limit]
  806.         cmp     [counter],eax
  807.         je      times_done
  808.         inc     [counter]
  809.         pop     esi
  810.         jmp     times_loop
  811.       times_done:
  812.         pop     eax
  813.         pop     [counter_limit]
  814.         pop     [counter]
  815.         jmp     instruction_assembled
  816.       negative_times:
  817.         cmp     [error_line],0
  818.         jne     zero_times
  819.         mov     eax,[current_line]
  820.         mov     [error_line],eax
  821.         mov     [error],invalid_value
  822.       zero_times:
  823.         call    skip_line
  824.         jmp     instruction_assembled
  825.  
  826. virtual_directive:
  827.         lods    byte [esi]
  828.         cmp     al,80h
  829.         jne     virtual_at_current
  830.         lods    byte [esi]
  831.         cmp     al,'('
  832.         jne     invalid_argument
  833.         cmp     byte [esi],'.'
  834.         je      invalid_value
  835.         call    get_address_value
  836.         mov     ebp,[address_symbol]
  837.         xor     ch,ch
  838.         or      bh,bh
  839.         jz      set_virtual
  840.         mov     ch,1
  841.         jmp     set_virtual
  842.       virtual_at_current:
  843.         dec     esi
  844.         mov     al,[labels_type]
  845.         mov     [value_type],al
  846.         mov     ebp,[org_symbol]
  847.         mov     eax,edi
  848.         xor     edx,edx
  849.         sub     eax,dword [org_origin]
  850.         sbb     edx,dword [org_origin+4]
  851.         mov     bx,word [org_registers]
  852.         mov     cx,word [org_registers+2]
  853.         xchg    bh,bl
  854.         xchg    ch,cl
  855.       set_virtual:
  856.         push    [org_registers]
  857.         mov     byte [org_registers],bh
  858.         mov     byte [org_registers+1],bl
  859.         mov     byte [org_registers+2],ch
  860.         mov     byte [org_registers+3],cl
  861.         call    allocate_structure_data
  862.         mov     word [ebx],virtual_directive-assembler
  863.         not     eax
  864.         not     edx
  865.         add     eax,1
  866.         adc     edx,0
  867.         add     eax,edi
  868.         adc     edx,0
  869.         xchg    dword [org_origin],eax
  870.         xchg    dword [org_origin+4],edx
  871.         mov     [ebx+10h],eax
  872.         mov     [ebx+14h],edx
  873.         pop     eax
  874.         mov     [ebx+18h],eax
  875.         mov     al,[virtual_data]
  876.         mov     [ebx+2],al
  877.         mov     al,[labels_type]
  878.         mov     [ebx+3],al
  879.         mov     eax,edi
  880.         xchg    eax,[org_start]
  881.         mov     [ebx+0Ch],eax
  882.         xchg    ebp,[org_symbol]
  883.         mov     [ebx+1Ch],ebp
  884.         mov     [ebx+8],edi
  885.         mov     eax,[current_line]
  886.         mov     [ebx+4],eax
  887.         or      [virtual_data],-1
  888.         mov     al,[value_type]
  889.         test    al,1
  890.         jnz     invalid_use_of_symbol
  891.         mov     [labels_type],al
  892.         jmp     instruction_assembled
  893.       allocate_structure_data:
  894.         mov     ebx,[structures_buffer]
  895.         sub     ebx,20h
  896.         cmp     ebx,[free_additional_memory]
  897.         jb      out_of_memory
  898.         mov     [structures_buffer],ebx
  899.         ret
  900.       find_structure_data:
  901.         mov     ebx,[structures_buffer]
  902.       scan_structures:
  903.         cmp     ebx,[additional_memory_end]
  904.         je      no_such_structure
  905.         cmp     ax,[ebx]
  906.         je      structure_data_found
  907.         add     ebx,20h
  908.         jmp     scan_structures
  909.       structure_data_found:
  910.         ret
  911.       no_such_structure:
  912.         stc
  913.         ret
  914.       end_virtual:
  915.         call    find_structure_data
  916.         jc      unexpected_instruction
  917.         mov     al,[ebx+2]
  918.         mov     [virtual_data],al
  919.         mov     al,[ebx+3]
  920.         mov     [labels_type],al
  921.         mov     eax,[ebx+10h]
  922.         mov     dword [org_origin],eax
  923.         mov     eax,[ebx+14h]
  924.         mov     dword [org_origin+4],eax
  925.         mov     eax,[ebx+18h]
  926.         mov     [org_registers],eax
  927.         mov     eax,[ebx+0Ch]
  928.         mov     [org_start],eax
  929.         mov     eax,[ebx+1Ch]
  930.         mov     [org_symbol],eax
  931.         mov     edi,[ebx+8]
  932.       remove_structure_data:
  933.         push    esi edi
  934.         mov     esi,[structures_buffer]
  935.         mov     ecx,ebx
  936.         sub     ecx,esi
  937.         lea     edi,[esi+20h]
  938.         mov     [structures_buffer],edi
  939.         shr     ecx,2
  940.         rep     movs dword [edi],[esi]
  941.         pop     edi esi
  942.         ret
  943. repeat_directive:
  944.         cmp     [prefixed_instruction],0
  945.         jne     unexpected_instruction
  946.         lods    byte [esi]
  947.         cmp     al,'('
  948.         jne     invalid_argument
  949.         cmp     byte [esi],'.'
  950.         je      invalid_value
  951.         call    get_dword_value
  952.         cmp     [next_pass_needed],0
  953.         jne     repeat_value_ok
  954.         cmp     [value_type],0
  955.         jne     invalid_use_of_symbol
  956.       repeat_value_ok:
  957.         cmp     eax,0
  958.         je      zero_repeat
  959.         jl      negative_repeat
  960.         call    allocate_structure_data
  961.         mov     word [ebx],repeat_directive-assembler
  962.         xchg    eax,[counter_limit]
  963.         mov     [ebx+10h],eax
  964.         mov     eax,1
  965.         xchg    eax,[counter]
  966.         mov     [ebx+14h],eax
  967.         mov     [ebx+8],esi
  968.         mov     eax,[current_line]
  969.         mov     [ebx+4],eax
  970.         jmp     instruction_assembled
  971.       end_repeat:
  972.         cmp     [prefixed_instruction],0
  973.         jne     unexpected_instruction
  974.         call    find_structure_data
  975.         jc      unexpected_instruction
  976.         mov     eax,[counter_limit]
  977.         inc     [counter]
  978.         cmp     [counter],eax
  979.         jbe     continue_repeating
  980.       stop_repeat:
  981.         mov     eax,[ebx+10h]
  982.         mov     [counter_limit],eax
  983.         mov     eax,[ebx+14h]
  984.         mov     [counter],eax
  985.         call    remove_structure_data
  986.         jmp     instruction_assembled
  987.       continue_repeating:
  988.         mov     esi,[ebx+8]
  989.         jmp     instruction_assembled
  990.       negative_repeat:
  991.         cmp     [error_line],0
  992.         jne     zero_repeat
  993.         mov     eax,[current_line]
  994.         mov     [error_line],eax
  995.         mov     [error],invalid_value
  996.       zero_repeat:
  997.         mov     al,[esi]
  998.         or      al,al
  999.         jz      missing_end_directive
  1000.         cmp     al,0Fh
  1001.         jne     extra_characters_on_line
  1002.         call    find_end_repeat
  1003.         jmp     instruction_assembled
  1004.       find_end_repeat:
  1005.         call    find_structure_end
  1006.         cmp     ax,repeat_directive-assembler
  1007.         jne     unexpected_instruction
  1008.         ret
  1009. while_directive:
  1010.         cmp     [prefixed_instruction],0
  1011.         jne     unexpected_instruction
  1012.         call    allocate_structure_data
  1013.         mov     word [ebx],while_directive-assembler
  1014.         mov     eax,1
  1015.         xchg    eax,[counter]
  1016.         mov     [ebx+10h],eax
  1017.         mov     [ebx+8],esi
  1018.         mov     eax,[current_line]
  1019.         mov     [ebx+4],eax
  1020.       do_while:
  1021.         push    ebx
  1022.         call    calculate_logical_expression
  1023.         or      al,al
  1024.         jnz     while_true
  1025.         mov     al,[esi]
  1026.         or      al,al
  1027.         jz      missing_end_directive
  1028.         cmp     al,0Fh
  1029.         jne     extra_characters_on_line
  1030.       stop_while:
  1031.         call    find_end_while
  1032.         pop     ebx
  1033.         mov     eax,[ebx+10h]
  1034.         mov     [counter],eax
  1035.         call    remove_structure_data
  1036.         jmp     instruction_assembled
  1037.       while_true:
  1038.         pop     ebx
  1039.         jmp     instruction_assembled
  1040.       end_while:
  1041.         cmp     [prefixed_instruction],0
  1042.         jne     unexpected_instruction
  1043.         call    find_structure_data
  1044.         jc      unexpected_instruction
  1045.         mov     eax,[ebx+4]
  1046.         mov     [current_line],eax
  1047.         inc     [counter]
  1048.         jz      too_many_repeats
  1049.         mov     esi,[ebx+8]
  1050.         jmp     do_while
  1051.       find_end_while:
  1052.         call    find_structure_end
  1053.         cmp     ax,while_directive-assembler
  1054.         jne     unexpected_instruction
  1055.         ret
  1056. if_directive:
  1057.         cmp     [prefixed_instruction],0
  1058.         jne     unexpected_instruction
  1059.         call    calculate_logical_expression
  1060.         mov     dl,al
  1061.         mov     al,[esi]
  1062.         or      al,al
  1063.         jz      missing_end_directive
  1064.         cmp     al,0Fh
  1065.         jne     extra_characters_on_line
  1066.         or      dl,dl
  1067.         jnz     if_true
  1068.         call    find_else
  1069.         jc      instruction_assembled
  1070.         mov     al,[esi]
  1071.         cmp     al,1
  1072.         jne     else_true
  1073.         cmp     word [esi+1],if_directive-assembler
  1074.         jne     else_true
  1075.         add     esi,4
  1076.         jmp     if_directive
  1077.       if_true:
  1078.         xor     al,al
  1079.       make_if_structure:
  1080.         call    allocate_structure_data
  1081.         mov     word [ebx],if_directive-assembler
  1082.         mov     byte [ebx+2],al
  1083.         mov     eax,[current_line]
  1084.         mov     [ebx+4],eax
  1085.         jmp     instruction_assembled
  1086.       else_true:
  1087.         or      al,al
  1088.         jz      missing_end_directive
  1089.         cmp     al,0Fh
  1090.         jne     extra_characters_on_line
  1091.         or      al,-1
  1092.         jmp     make_if_structure
  1093.       else_directive:
  1094.         cmp     [prefixed_instruction],0
  1095.         jne     unexpected_instruction
  1096.         mov     ax,if_directive-assembler
  1097.         call    find_structure_data
  1098.         jc      unexpected_instruction
  1099.         cmp     byte [ebx+2],0
  1100.         jne     unexpected_instruction
  1101.       found_else:
  1102.         mov     al,[esi]
  1103.         cmp     al,1
  1104.         jne     skip_else
  1105.         cmp     word [esi+1],if_directive-assembler
  1106.         jne     skip_else
  1107.         add     esi,4
  1108.         call    find_else
  1109.         jnc     found_else
  1110.         call    remove_structure_data
  1111.         jmp     instruction_assembled
  1112.       skip_else:
  1113.         or      al,al
  1114.         jz      missing_end_directive
  1115.         cmp     al,0Fh
  1116.         jne     extra_characters_on_line
  1117.         call    find_end_if
  1118.         call    remove_structure_data
  1119.         jmp     instruction_assembled
  1120.       end_if:
  1121.         cmp     [prefixed_instruction],0
  1122.         jne     unexpected_instruction
  1123.         call    find_structure_data
  1124.         jc      unexpected_instruction
  1125.         call    remove_structure_data
  1126.         jmp     instruction_assembled
  1127.       find_else:
  1128.         call    find_structure_end
  1129.         cmp     ax,else_directive-assembler
  1130.         je      else_found
  1131.         cmp     ax,if_directive-assembler
  1132.         jne     unexpected_instruction
  1133.         stc
  1134.         ret
  1135.       else_found:
  1136.         clc
  1137.         ret
  1138.       find_end_if:
  1139.         call    find_structure_end
  1140.         cmp     ax,if_directive-assembler
  1141.         jne     unexpected_instruction
  1142.         ret
  1143.       find_structure_end:
  1144.         push    [error_line]
  1145.         mov     eax,[current_line]
  1146.         mov     [error_line],eax
  1147.       find_end_directive:
  1148.         call    skip_line
  1149.         lods    byte [esi]
  1150.         cmp     al,0Fh
  1151.         jne     no_end_directive
  1152.         lods    dword [esi]
  1153.         mov     [current_line],eax
  1154.       skip_labels:
  1155.         cmp     byte [esi],2
  1156.         jne     labels_ok
  1157.         add     esi,6
  1158.         jmp     skip_labels
  1159.       labels_ok:
  1160.         cmp     byte [esi],1
  1161.         jne     find_end_directive
  1162.         mov     ax,[esi+1]
  1163.         cmp     ax,prefix_instruction-assembler
  1164.         je      find_end_directive
  1165.         add     esi,4
  1166.         cmp     ax,repeat_directive-assembler
  1167.         je      skip_repeat
  1168.         cmp     ax,while_directive-assembler
  1169.         je      skip_while
  1170.         cmp     ax,if_directive-assembler
  1171.         je      skip_if
  1172.         cmp     ax,else_directive-assembler
  1173.         je      structure_end
  1174.         cmp     ax,end_directive-assembler
  1175.         jne     find_end_directive
  1176.         cmp     byte [esi],1
  1177.         jne     find_end_directive
  1178.         mov     ax,[esi+1]
  1179.         add     esi,4
  1180.         cmp     ax,repeat_directive-assembler
  1181.         je      structure_end
  1182.         cmp     ax,while_directive-assembler
  1183.         je      structure_end
  1184.         cmp     ax,if_directive-assembler
  1185.         jne     find_end_directive
  1186.       structure_end:
  1187.         pop     [error_line]
  1188.         ret
  1189.       no_end_directive:
  1190.         mov     eax,[error_line]
  1191.         mov     [current_line],eax
  1192.         jmp     missing_end_directive
  1193.       skip_repeat:
  1194.         call    find_end_repeat
  1195.         jmp     find_end_directive
  1196.       skip_while:
  1197.         call    find_end_while
  1198.         jmp     find_end_directive
  1199.       skip_if:
  1200.         call    skip_if_block
  1201.         jmp     find_end_directive
  1202.       skip_if_block:
  1203.         call    find_else
  1204.         jc      if_block_skipped
  1205.         cmp     byte [esi],1
  1206.         jne     skip_after_else
  1207.         cmp     word [esi+1],if_directive-assembler
  1208.         jne     skip_after_else
  1209.         add     esi,4
  1210.         jmp     skip_if_block
  1211.       skip_after_else:
  1212.         call    find_end_if
  1213.       if_block_skipped:
  1214.         ret
  1215. end_directive:
  1216.         lods    byte [esi]
  1217.         cmp     al,1
  1218.         jne     invalid_argument
  1219.         lods    word [esi]
  1220.         inc     esi
  1221.         cmp     ax,virtual_directive-assembler
  1222.         je      end_virtual
  1223.         cmp     ax,repeat_directive-assembler
  1224.         je      end_repeat
  1225.         cmp     ax,while_directive-assembler
  1226.         je      end_while
  1227.         cmp     ax,if_directive-assembler
  1228.         je      end_if
  1229.         cmp     ax,data_directive-assembler
  1230.         je      end_data
  1231.         jmp     invalid_argument
  1232. break_directive:
  1233.         mov     ebx,[structures_buffer]
  1234.         mov     al,[esi]
  1235.         or      al,al
  1236.         jz      find_breakable_structure
  1237.         cmp     al,0Fh
  1238.         jne     extra_characters_on_line
  1239.       find_breakable_structure:
  1240.         cmp     ebx,[additional_memory_end]
  1241.         je      unexpected_instruction
  1242.         mov     ax,[ebx]
  1243.         cmp     ax,repeat_directive-assembler
  1244.         je      break_repeat
  1245.         cmp     ax,while_directive-assembler
  1246.         je      break_while
  1247.         cmp     ax,if_directive-assembler
  1248.         je      break_if
  1249.         add     ebx,20h
  1250.         jmp     find_breakable_structure
  1251.       break_if:
  1252.         push    [current_line]
  1253.         mov     eax,[ebx+4]
  1254.         mov     [current_line],eax
  1255.         call    remove_structure_data
  1256.         call    skip_if_block
  1257.         pop     [current_line]
  1258.         mov     ebx,[structures_buffer]
  1259.         jmp     find_breakable_structure
  1260.       break_repeat:
  1261.         push    ebx
  1262.         call    find_end_repeat
  1263.         pop     ebx
  1264.         jmp     stop_repeat
  1265.       break_while:
  1266.         push    ebx
  1267.         jmp     stop_while
  1268.  
  1269. data_bytes:
  1270.         call    define_data
  1271.         lods    byte [esi]
  1272.         cmp     al,'('
  1273.         je      get_byte
  1274.         cmp     al,'?'
  1275.         jne     invalid_argument
  1276.         mov     eax,edi
  1277.         mov     byte [edi],0
  1278.         inc     edi
  1279.         jmp     undefined_data
  1280.       get_byte:
  1281.         cmp     byte [esi],0
  1282.         je      get_string
  1283.         call    get_byte_value
  1284.         stos    byte [edi]
  1285.         ret
  1286.       get_string:
  1287.         inc     esi
  1288.         lods    dword [esi]
  1289.         mov     ecx,eax
  1290.         lea     eax,[edi+ecx]
  1291.         cmp     eax,[display_buffer]
  1292.         ja      out_of_memory
  1293.         rep     movs byte [edi],[esi]
  1294.         inc     esi
  1295.         ret
  1296.       undefined_data:
  1297.         cmp     [virtual_data],0
  1298.         je      mark_undefined_data
  1299.         ret
  1300.       mark_undefined_data:
  1301.         cmp     eax,[undefined_data_end]
  1302.         je      undefined_data_ok
  1303.         mov     [undefined_data_start],eax
  1304.       undefined_data_ok:
  1305.         mov     [undefined_data_end],edi
  1306.         ret
  1307.       define_data:
  1308.         cmp     edi,[display_buffer]
  1309.         jae     out_of_memory
  1310.         cmp     byte [esi],'('
  1311.         jne     simple_data_value
  1312.         mov     ebx,esi
  1313.         inc     esi
  1314.         call    skip_expression
  1315.         xchg    esi,ebx
  1316.         cmp     byte [ebx],81h
  1317.         jne     simple_data_value
  1318.         inc     esi
  1319.         call    get_dword_value
  1320.         cmp     [next_pass_needed],0
  1321.         jne     dup_value_ok
  1322.         cmp     [value_type],0
  1323.         jne     invalid_use_of_symbol
  1324.       dup_value_ok:
  1325.         inc     esi
  1326.         cmp     eax,0
  1327.         jg      dup_positive
  1328.         cmp     [error_line],0
  1329.         jne     dup_invalid
  1330.         mov     eax,[current_line]
  1331.         mov     [error_line],eax
  1332.         mov     [error],invalid_value
  1333.       dup_invalid:
  1334.         mov     eax,1
  1335.       dup_positive:
  1336.         cmp     byte [esi],'{'
  1337.         jne     duplicate_single_data_value
  1338.         inc     esi
  1339.       duplicate_data:
  1340.         push    eax esi
  1341.       duplicated_values:
  1342.         cmp     edi,[display_buffer]
  1343.         jae     out_of_memory
  1344.         call    near dword [esp+8]
  1345.         lods    byte [esi]
  1346.         cmp     al,','
  1347.         je      duplicated_values
  1348.         cmp     al,'}'
  1349.         jne     invalid_argument
  1350.         pop     ebx eax
  1351.         dec     eax
  1352.         jz      data_defined
  1353.         mov     esi,ebx
  1354.         jmp     duplicate_data
  1355.       duplicate_single_data_value:
  1356.         cmp     edi,[display_buffer]
  1357.         jae     out_of_memory
  1358.         push    eax esi
  1359.         call    near dword [esp+8]
  1360.         pop     ebx eax
  1361.         dec     eax
  1362.         jz      data_defined
  1363.         mov     esi,ebx
  1364.         jmp     duplicate_single_data_value
  1365.       simple_data_value:
  1366.         cmp     edi,[display_buffer]
  1367.         jae     out_of_memory
  1368.         call    near dword [esp]
  1369.       data_defined:
  1370.         lods    byte [esi]
  1371.         cmp     al,','
  1372.         je      define_data
  1373.         dec     esi
  1374.         add     esp,4
  1375.         jmp     instruction_assembled
  1376. data_unicode:
  1377.         or      [base_code],-1
  1378.         jmp     define_words
  1379. data_words:
  1380.         mov     [base_code],0
  1381.       define_words:
  1382.         call    define_data
  1383.         lods    byte [esi]
  1384.         cmp     al,'('
  1385.         je      get_word
  1386.         cmp     al,'?'
  1387.         jne     invalid_argument
  1388.         mov     eax,edi
  1389.         mov     word [edi],0
  1390.         scas    word [edi]
  1391.         jmp     undefined_data
  1392.         ret
  1393.       get_word:
  1394.         cmp     [base_code],0
  1395.         je      word_data_value
  1396.         cmp     byte [esi],0
  1397.         je      word_string
  1398.       word_data_value:
  1399.         call    get_word_value
  1400.         call    mark_relocation
  1401.         stos    word [edi]
  1402.         ret
  1403.       word_string:
  1404.         inc     esi
  1405.         lods    dword [esi]
  1406.         mov     ecx,eax
  1407.         jecxz   word_string_ok
  1408.         lea     eax,[edi+ecx*2]
  1409.         cmp     eax,[display_buffer]
  1410.         ja      out_of_memory
  1411.         xor     ah,ah
  1412.       copy_word_string:
  1413.         lods    byte [esi]
  1414.         stos    word [edi]
  1415.         loop    copy_word_string
  1416.       word_string_ok:
  1417.         inc     esi
  1418.         ret
  1419. data_dwords:
  1420.         call    define_data
  1421.         lods    byte [esi]
  1422.         cmp     al,'('
  1423.         je      get_dword
  1424.         cmp     al,'?'
  1425.         jne     invalid_argument
  1426.         mov     eax,edi
  1427.         mov     dword [edi],0
  1428.         scas    dword [edi]
  1429.         jmp     undefined_data
  1430.       get_dword:
  1431.         push    esi
  1432.         call    get_dword_value
  1433.         pop     ebx
  1434.         cmp     byte [esi],':'
  1435.         je      complex_dword
  1436.         call    mark_relocation
  1437.         stos    dword [edi]
  1438.         ret
  1439.       complex_dword:
  1440.         mov     esi,ebx
  1441.         cmp     byte [esi],'.'
  1442.         je      invalid_value
  1443.         call    get_word_value
  1444.         push    eax
  1445.         inc     esi
  1446.         lods    byte [esi]
  1447.         cmp     al,'('
  1448.         jne     invalid_operand
  1449.         mov     al,[value_type]
  1450.         push    eax
  1451.         cmp     byte [esi],'.'
  1452.         je      invalid_value
  1453.         call    get_word_value
  1454.         call    mark_relocation
  1455.         stos    word [edi]
  1456.         pop     eax
  1457.         mov     [value_type],al
  1458.         pop     eax
  1459.         call    mark_relocation
  1460.         stos    word [edi]
  1461.         ret
  1462. data_pwords:
  1463.         call    define_data
  1464.         lods    byte [esi]
  1465.         cmp     al,'('
  1466.         je      get_pword
  1467.         cmp     al,'?'
  1468.         jne     invalid_argument
  1469.         mov     eax,edi
  1470.         mov     dword [edi],0
  1471.         scas    dword [edi]
  1472.         mov     word [edi],0
  1473.         scas    word [edi]
  1474.         jmp     undefined_data
  1475.       get_pword:
  1476.         push    esi
  1477.         call    get_pword_value
  1478.         pop     ebx
  1479.         cmp     byte [esi],':'
  1480.         je      complex_pword
  1481.         call    mark_relocation
  1482.         stos    dword [edi]
  1483.         mov     ax,dx
  1484.         stos    word [edi]
  1485.         ret
  1486.       complex_pword:
  1487.         mov     esi,ebx
  1488.         cmp     byte [esi],'.'
  1489.         je      invalid_value
  1490.         call    get_word_value
  1491.         push    eax
  1492.         inc     esi
  1493.         lods    byte [esi]
  1494.         cmp     al,'('
  1495.         jne     invalid_operand
  1496.         mov     al,[value_type]
  1497.         push    eax
  1498.         cmp     byte [esi],'.'
  1499.         je      invalid_value
  1500.         call    get_dword_value
  1501.         call    mark_relocation
  1502.         stos    dword [edi]
  1503.         pop     eax
  1504.         mov     [value_type],al
  1505.         pop     eax
  1506.         call    mark_relocation
  1507.         stos    word [edi]
  1508.         ret
  1509. data_qwords:
  1510.         call    define_data
  1511.         lods    byte [esi]
  1512.         cmp     al,'('
  1513.         je      get_qword
  1514.         cmp     al,'?'
  1515.         jne     invalid_argument
  1516.         mov     eax,edi
  1517.         mov     dword [edi],0
  1518.         scas    dword [edi]
  1519.         mov     dword [edi],0
  1520.         scas    dword [edi]
  1521.         jmp     undefined_data
  1522.       get_qword:
  1523.         call    get_qword_value
  1524.         call    mark_relocation
  1525.         stos    dword [edi]
  1526.         mov     eax,edx
  1527.         stos    dword [edi]
  1528.         ret
  1529. data_twords:
  1530.         call    define_data
  1531.         lods    byte [esi]
  1532.         cmp     al,'('
  1533.         je      get_tword
  1534.         cmp     al,'?'
  1535.         jne     invalid_argument
  1536.         mov     eax,edi
  1537.         mov     dword [edi],0
  1538.         scas    dword [edi]
  1539.         mov     dword [edi],0
  1540.         scas    dword [edi]
  1541.         mov     word [edi],0
  1542.         scas    word [edi]
  1543.         jmp     undefined_data
  1544.       get_tword:
  1545.         cmp     byte [esi],'.'
  1546.         jne     complex_tword
  1547.         inc     esi
  1548.         cmp     word [esi+8],8000h
  1549.         je      fp_zero_tword
  1550.         mov     eax,[esi]
  1551.         stos    dword [edi]
  1552.         mov     eax,[esi+4]
  1553.         stos    dword [edi]
  1554.         mov     ax,[esi+8]
  1555.         add     ax,3FFFh
  1556.         cmp     ax,8000h
  1557.         jae     value_out_of_range
  1558.         mov     bl,[esi+11]
  1559.         shl     bx,15
  1560.         or      ax,bx
  1561.         stos    word [edi]
  1562.         add     esi,13
  1563.         ret
  1564.       fp_zero_tword:
  1565.         xor     eax,eax
  1566.         stos    dword [edi]
  1567.         stos    dword [edi]
  1568.         mov     al,[esi+11]
  1569.         shl     ax,15
  1570.         stos    word [edi]
  1571.         add     esi,13
  1572.         ret
  1573.       complex_tword:
  1574.         call    get_word_value
  1575.         push    eax
  1576.         inc     esi
  1577.         lods    byte [esi]
  1578.         cmp     al,'('
  1579.         jne     invalid_operand
  1580.         mov     al,[value_type]
  1581.         push    eax
  1582.         cmp     byte [esi],'.'
  1583.         je      invalid_value
  1584.         call    get_qword_value
  1585.         call    mark_relocation
  1586.         stos    dword [edi]
  1587.         mov     eax,edx
  1588.         stos    dword [edi]
  1589.         pop     eax
  1590.         mov     [value_type],al
  1591.         pop     eax
  1592.         call    mark_relocation
  1593.         stos    word [edi]
  1594.         ret
  1595. data_file:
  1596.         lods    word [esi]
  1597.         cmp     ax,'('
  1598.         jne     invalid_argument
  1599.         add     esi,4
  1600.         call    open_binary_file
  1601.         mov     eax,[esi-4]
  1602.         lea     esi,[esi+eax+1]
  1603.         mov     al,2
  1604.         xor     edx,edx
  1605.         call    lseek
  1606.         push    eax
  1607.         xor     edx,edx
  1608.         cmp     byte [esi],':'
  1609.         jne     position_ok
  1610.         inc     esi
  1611.         cmp     byte [esi],'('
  1612.         jne     invalid_argument
  1613.         inc     esi
  1614.         cmp     byte [esi],'.'
  1615.         je      invalid_value
  1616.         push    ebx
  1617.         call    get_dword_value
  1618.         pop     ebx
  1619.         mov     edx,eax
  1620.         sub     [esp],edx
  1621.       position_ok:
  1622.         cmp     byte [esi],','
  1623.         jne     size_ok
  1624.         inc     esi
  1625.         cmp     byte [esi],'('
  1626.         jne     invalid_argument
  1627.         inc     esi
  1628.         cmp     byte [esi],'.'
  1629.         je      invalid_value
  1630.         push    ebx edx
  1631.         call    get_dword_value
  1632.         pop     edx ebx
  1633.         mov     [esp],eax
  1634.       size_ok:
  1635.         xor     al,al
  1636.         call    lseek
  1637.         pop     ecx
  1638.         mov     edx,edi
  1639.         add     edi,ecx
  1640.         jc      out_of_memory
  1641.         cmp     edi,[display_buffer]
  1642.         ja      out_of_memory
  1643.         call    read
  1644.         jc      error_reading_file
  1645.         call    close
  1646.         lods    byte [esi]
  1647.         cmp     al,','
  1648.         je      data_file
  1649.         dec     esi
  1650.         jmp     instruction_assembled
  1651.       open_binary_file:
  1652.         push    esi
  1653.         push    edi
  1654.         mov     esi,[current_line]
  1655.         mov     esi,[esi]
  1656.       get_current_path:
  1657.         lodsb
  1658.         stosb
  1659.         or      al,al
  1660.         jnz     get_current_path
  1661.       cut_current_path:
  1662.         cmp     edi,[esp]
  1663.         je      current_path_ok
  1664.         cmp     byte [edi-1],'\'
  1665.         je      current_path_ok
  1666.         cmp     byte [edi-1],'/'
  1667.         je      current_path_ok
  1668.         dec     edi
  1669.         jmp     cut_current_path
  1670.       current_path_ok:
  1671.         mov     esi,[esp+4]
  1672.         call    preprocess_path
  1673.         pop     edx
  1674.         mov     esi,edx
  1675.         call    open
  1676.         jnc     file_opened
  1677.         mov     edi,esi
  1678.         mov     esi,[esp]
  1679.         push    edi
  1680.         call    preprocess_path
  1681.         pop     edx
  1682.         mov     esi,edx
  1683.         call    open
  1684.         jc      file_not_found
  1685.       file_opened:
  1686.         mov     edi,esi
  1687.         pop     esi
  1688.         ret
  1689. reserve_bytes:
  1690.         lods    byte [esi]
  1691.         cmp     al,'('
  1692.         jne     invalid_argument
  1693.         cmp     byte [esi],'.'
  1694.         je      invalid_value
  1695.         call    get_dword_value
  1696.         cmp     [next_pass_needed],0
  1697.         jne     rb_value_ok
  1698.         cmp     [value_type],0
  1699.         jne     invalid_use_of_symbol
  1700.       rb_value_ok:
  1701.         cmp     eax,0
  1702.         jl      reserve_negative
  1703.         mov     ecx,eax
  1704.         mov     edx,ecx
  1705.         add     edx,edi
  1706.         jc      out_of_memory
  1707.         cmp     edx,[display_buffer]
  1708.         ja      out_of_memory
  1709.         push    edi
  1710.         cmp     [next_pass_needed],0
  1711.         je      zero_bytes
  1712.         add     edi,ecx
  1713.         jmp     reserved_data
  1714.       zero_bytes:
  1715.         xor     eax,eax
  1716.         shr     ecx,1
  1717.         jnc     bytes_stosb_ok
  1718.         stos    byte [edi]
  1719.       bytes_stosb_ok:
  1720.         shr     ecx,1
  1721.         jnc     bytes_stosw_ok
  1722.         stos    word [edi]
  1723.       bytes_stosw_ok:
  1724.         rep     stos dword [edi]
  1725.       reserved_data:
  1726.         pop     eax
  1727.         call    undefined_data
  1728.         jmp     instruction_assembled
  1729.       reserve_negative:
  1730.         cmp     [error_line],0
  1731.         jne     instruction_assembled
  1732.         mov     eax,[current_line]
  1733.         mov     [error_line],eax
  1734.         mov     [error],invalid_value
  1735.         jmp     instruction_assembled
  1736. reserve_words:
  1737.         lods    byte [esi]
  1738.         cmp     al,'('
  1739.         jne     invalid_argument
  1740.         cmp     byte [esi],'.'
  1741.         je      invalid_value
  1742.         call    get_dword_value
  1743.         cmp     [next_pass_needed],0
  1744.         jne     rw_value_ok
  1745.         cmp     [value_type],0
  1746.         jne     invalid_use_of_symbol
  1747.       rw_value_ok:
  1748.         cmp     eax,0
  1749.         jl      reserve_negative
  1750.         mov     ecx,eax
  1751.         mov     edx,ecx
  1752.         shl     edx,1
  1753.         jc      out_of_memory
  1754.         add     edx,edi
  1755.         jc      out_of_memory
  1756.         cmp     edx,[display_buffer]
  1757.         ja      out_of_memory
  1758.         push    edi
  1759.         cmp     [next_pass_needed],0
  1760.         je      zero_words
  1761.         lea     edi,[edi+ecx*2]
  1762.         jmp     reserved_data
  1763.       zero_words:
  1764.         xor     eax,eax
  1765.         shr     ecx,1
  1766.         jnc     words_stosw_ok
  1767.         stos    word [edi]
  1768.       words_stosw_ok:
  1769.         rep     stos dword [edi]
  1770.         jmp     reserved_data
  1771. reserve_dwords:
  1772.         lods    byte [esi]
  1773.         cmp     al,'('
  1774.         jne     invalid_argument
  1775.         cmp     byte [esi],'.'
  1776.         je      invalid_value
  1777.         call    get_dword_value
  1778.         cmp     [next_pass_needed],0
  1779.         jne     rd_value_ok
  1780.         cmp     [value_type],0
  1781.         jne     invalid_use_of_symbol
  1782.       rd_value_ok:
  1783.         cmp     eax,0
  1784.         jl      reserve_negative
  1785.         mov     ecx,eax
  1786.         mov     edx,ecx
  1787.         shl     edx,1
  1788.         jc      out_of_memory
  1789.         shl     edx,1
  1790.         jc      out_of_memory
  1791.         add     edx,edi
  1792.         jc      out_of_memory
  1793.         cmp     edx,[display_buffer]
  1794.         ja      out_of_memory
  1795.         push    edi
  1796.         cmp     [next_pass_needed],0
  1797.         je      zero_dwords
  1798.         lea     edi,[edi+ecx*4]
  1799.         jmp     reserved_data
  1800.       zero_dwords:
  1801.         xor     eax,eax
  1802.         rep     stos dword [edi]
  1803.         jmp     reserved_data
  1804. reserve_pwords:
  1805.         lods    byte [esi]
  1806.         cmp     al,'('
  1807.         jne     invalid_argument
  1808.         cmp     byte [esi],'.'
  1809.         je      invalid_value
  1810.         call    get_dword_value
  1811.         cmp     [next_pass_needed],0
  1812.         jne     rp_value_ok
  1813.         cmp     [value_type],0
  1814.         jne     invalid_use_of_symbol
  1815.       rp_value_ok:
  1816.         cmp     eax,0
  1817.         jl      reserve_negative
  1818.         mov     ecx,eax
  1819.         shl     ecx,1
  1820.         jc      out_of_memory
  1821.         add     ecx,eax
  1822.         mov     edx,ecx
  1823.         shl     edx,1
  1824.         jc      out_of_memory
  1825.         add     edx,edi
  1826.         jc      out_of_memory
  1827.         cmp     edx,[display_buffer]
  1828.         ja      out_of_memory
  1829.         push    edi
  1830.         cmp     [next_pass_needed],0
  1831.         je      zero_words
  1832.         lea     edi,[edi+ecx*2]
  1833.         jmp     reserved_data
  1834. reserve_qwords:
  1835.         lods    byte [esi]
  1836.         cmp     al,'('
  1837.         jne     invalid_argument
  1838.         cmp     byte [esi],'.'
  1839.         je      invalid_value
  1840.         call    get_dword_value
  1841.         cmp     [next_pass_needed],0
  1842.         jne     rq_value_ok
  1843.         cmp     [value_type],0
  1844.         jne     invalid_use_of_symbol
  1845.       rq_value_ok:
  1846.         cmp     eax,0
  1847.         jl      reserve_negative
  1848.         mov     ecx,eax
  1849.         shl     ecx,1
  1850.         jc      out_of_memory
  1851.         mov     edx,ecx
  1852.         shl     edx,1
  1853.         jc      out_of_memory
  1854.         shl     edx,1
  1855.         jc      out_of_memory
  1856.         add     edx,edi
  1857.         jc      out_of_memory
  1858.         cmp     edx,[display_buffer]
  1859.         ja      out_of_memory
  1860.         push    edi
  1861.         cmp     [next_pass_needed],0
  1862.         je      zero_dwords
  1863.         lea     edi,[edi+ecx*4]
  1864.         jmp     reserved_data
  1865. reserve_twords:
  1866.         lods    byte [esi]
  1867.         cmp     al,'('
  1868.         jne     invalid_argument
  1869.         cmp     byte [esi],'.'
  1870.         je      invalid_value
  1871.         call    get_dword_value
  1872.         cmp     [next_pass_needed],0
  1873.         jne     rt_value_ok
  1874.         cmp     [value_type],0
  1875.         jne     invalid_use_of_symbol
  1876.       rt_value_ok:
  1877.         cmp     eax,0
  1878.         jl      reserve_negative
  1879.         mov     ecx,eax
  1880.         shl     ecx,2
  1881.         jc      out_of_memory
  1882.         add     ecx,eax
  1883.         mov     edx,ecx
  1884.         shl     edx,1
  1885.         jc      out_of_memory
  1886.         add     edx,edi
  1887.         jc      out_of_memory
  1888.         cmp     edx,[display_buffer]
  1889.         ja      out_of_memory
  1890.         push    edi
  1891.         cmp     [next_pass_needed],0
  1892.         je      zero_words
  1893.         lea     edi,[edi+ecx*2]
  1894.         jmp     reserved_data
  1895. align_directive:
  1896.         lods    byte [esi]
  1897.         cmp     al,'('
  1898.         jne     invalid_argument
  1899.         cmp     byte [esi],'.'
  1900.         je      invalid_value
  1901.         call    get_dword_value
  1902.         cmp     [value_type],0
  1903.         jne     invalid_use_of_symbol
  1904.         mov     edx,eax
  1905.         dec     edx
  1906.         test    eax,edx
  1907.         jnz     negative_times
  1908.         or      eax,eax
  1909.         jz      negative_times
  1910.         cmp     eax,1
  1911.         je      instruction_assembled
  1912.         mov     ecx,edi
  1913.         sub     ecx,dword [org_origin]
  1914.         cmp     [org_registers],0
  1915.         jne     section_not_aligned_enough
  1916.         cmp     [labels_type],0
  1917.         je      make_alignment
  1918.         cmp     [output_format],3
  1919.         je      pe_alignment
  1920.         mov     ebx,[org_symbol]
  1921.         cmp     byte [ebx],0
  1922.         jne     section_not_aligned_enough
  1923.         cmp     eax,[ebx+10h]
  1924.         jbe     make_alignment
  1925.         jmp     section_not_aligned_enough
  1926.       pe_alignment:
  1927.         cmp     eax,1000h
  1928.         ja      section_not_aligned_enough
  1929.       make_alignment:
  1930.         dec     eax
  1931.         and     ecx,eax
  1932.         jz      instruction_assembled
  1933.         neg     ecx
  1934.         add     ecx,eax
  1935.         inc     ecx
  1936.         mov     edx,ecx
  1937.         add     edx,edi
  1938.         jc      out_of_memory
  1939.         cmp     edx,[display_buffer]
  1940.         ja      out_of_memory
  1941.         push    edi
  1942.         cmp     [next_pass_needed],0
  1943.         je      nops
  1944.         add     edi,ecx
  1945.         jmp     reserved_data
  1946.       nops:
  1947.         mov     eax,90909090h
  1948.         shr     ecx,1
  1949.         jnc     nops_stosb_ok
  1950.         stos    byte [edi]
  1951.       nops_stosb_ok:
  1952.         shr     ecx,1
  1953.         jnc     nops_stosw_ok
  1954.         stos    word [edi]
  1955.       nops_stosw_ok:
  1956.         rep     stos dword [edi]
  1957.         jmp     reserved_data
  1958.