Subversion Repositories Kolibri OS

Rev

Rev 31 | Go to most recent revision | 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_relative_offset
  622.         neg     eax
  623.         cmp     [next_pass_needed],0
  624.         jne     load_address_ok
  625.         cmp     [value_type],0
  626.         jne     invalid_use_of_symbol
  627.       load_address_ok:
  628.         push    esi edi
  629.         mov     esi,edi
  630.         sub     esi,eax
  631.         jc      bad_load_address
  632.         cmp     esi,[org_start]
  633.         jb      bad_load_address
  634.         mov     edi,value
  635.         movzx   ecx,[operand_size]
  636.         cmp     ecx,eax
  637.         ja      bad_load_address
  638.         rep     movs byte [edi],[esi]
  639.         jmp     value_loaded
  640.       bad_load_address:
  641.         cmp     [error_line],0
  642.         jne     value_loaded
  643.         mov     eax,[current_line]
  644.         mov     [error_line],eax
  645.         mov     [error],value_out_of_range
  646.       value_loaded:
  647.         pop     edi esi
  648.         mov     eax,dword [value]
  649.         mov     edx,dword [value+4]
  650.         pop     ebx
  651.         xor     cx,cx
  652.         jmp     make_constant
  653. store_directive:
  654.         cmp     byte [esi],11h
  655.         je      sized_store
  656.         lods    byte [esi]
  657.         cmp     al,'('
  658.         jne     invalid_argument
  659.         call    get_byte_value
  660.         xor     edx,edx
  661.         movzx   eax,al
  662.         mov     [operand_size],1
  663.         jmp     store_value_ok
  664.       sized_store:
  665.         call    get_value
  666.       store_value_ok:
  667.         cmp     [value_type],0
  668.         jne     invalid_use_of_symbol
  669.         mov     dword [value],eax
  670.         mov     dword [value+4],edx
  671.         lods    word [esi]
  672.         cmp     ax,80h+'(' shl 8
  673.         jne     invalid_argument
  674.         cmp     byte [esi],'.'
  675.         je      invalid_value
  676.         call    get_relative_offset
  677.         neg     eax
  678.         cmp     [next_pass_needed],0
  679.         jne     store_address_ok
  680.         cmp     [value_type],0
  681.         jne     invalid_use_of_symbol
  682.       store_address_ok:
  683.         push    esi edi
  684.         sub     edi,eax
  685.         jc      bad_store_address
  686.         cmp     edi,[org_start]
  687.         jb      bad_store_address
  688.         mov     esi,value
  689.         movzx   ecx,[operand_size]
  690.         cmp     ecx,eax
  691.         ja      bad_store_address
  692.         rep     movs byte [edi],[esi]
  693.         mov     eax,edi
  694.         pop     edi esi
  695.         cmp     edi,[undefined_data_end]
  696.         jne     instruction_assembled
  697.         cmp     eax,[undefined_data_start]
  698.         jbe     instruction_assembled
  699.         mov     [undefined_data_start],eax
  700.         jmp     instruction_assembled
  701.       bad_store_address:
  702.         pop     edi esi
  703.         cmp     [error_line],0
  704.         jne     instruction_assembled
  705.         mov     eax,[current_line]
  706.         mov     [error_line],eax
  707.         mov     [error],value_out_of_range
  708.         jmp     instruction_assembled
  709.  
  710. display_directive:
  711.         lods    byte [esi]
  712.         cmp     al,'('
  713.         jne     invalid_argument
  714.         cmp     byte [esi],0
  715.         jne     display_byte
  716.         inc     esi
  717.         lods    dword [esi]
  718.         mov     ecx,eax
  719.         push    edi
  720.         mov     edi,[display_buffer]
  721.         sub     edi,4
  722.         sub     edi,eax
  723.         mov     [display_buffer],edi
  724.         rep     movs byte [edi],[esi]
  725.         stos    dword [edi]
  726.         pop     edi
  727.         inc     esi
  728.         jmp     display_next
  729.       display_byte:
  730.         call    get_byte_value
  731.         push    edi
  732.         mov     edi,[display_buffer]
  733.         sub     edi,4+1
  734.         mov     [display_buffer],edi
  735.         stos    byte [edi]
  736.         mov     eax,1
  737.         stos    dword [edi]
  738.         pop     edi
  739.       display_next:
  740.         cmp     edi,[display_buffer]
  741.         ja      out_of_memory
  742.         lods    byte [esi]
  743.         cmp     al,','
  744.         je      display_directive
  745.         dec     esi
  746.         jmp     instruction_assembled
  747. flush_display_buffer:
  748.         mov     eax,[display_buffer]
  749.         or      eax,eax
  750.         jz      display_done
  751.         mov     esi,[labels_list]
  752.         cmp     esi,eax
  753.         je      display_done
  754.       display_messages:
  755.         sub     esi,4
  756.         mov     ecx,[esi]
  757.         sub     esi,ecx
  758.         push    esi
  759.         call    display_block
  760.         pop     esi
  761.         cmp     esi,[display_buffer]
  762.         jne     display_messages
  763.         mov     eax,[labels_list]
  764.         mov     [display_buffer],eax
  765.       display_done:
  766.         ret
  767. times_directive:
  768.         lods    byte [esi]
  769.         cmp     al,'('
  770.         jne     invalid_argument
  771.         cmp     byte [esi],'.'
  772.         je      invalid_value
  773.         call    get_dword_value
  774.         cmp     [next_pass_needed],0
  775.         jne     times_value_ok
  776.         cmp     [value_type],0
  777.         jne     invalid_use_of_symbol
  778.       times_value_ok:
  779.         cmp     eax,0
  780.         je      zero_times
  781.         jl      negative_times
  782.         cmp     byte [esi],':'
  783.         jne     times_argument_ok
  784.         inc     esi
  785.       times_argument_ok:
  786.         push    [counter]
  787.         push    [counter_limit]
  788.         mov     [counter_limit],eax
  789.         mov     [counter],1
  790.       times_loop:
  791.         mov     eax,esp
  792.         sub     eax,100h
  793.         jc      stack_overflow
  794.         cmp     eax,[stack_limit]
  795.         jb      stack_overflow
  796.         push    esi
  797.         or      [prefixed_instruction],-1
  798.         call    continue_line
  799.         mov     eax,[counter_limit]
  800.         cmp     [counter],eax
  801.         je      times_done
  802.         inc     [counter]
  803.         pop     esi
  804.         jmp     times_loop
  805.       times_done:
  806.         pop     eax
  807.         pop     [counter_limit]
  808.         pop     [counter]
  809.         jmp     instruction_assembled
  810.       negative_times:
  811.         cmp     [error_line],0
  812.         jne     zero_times
  813.         mov     eax,[current_line]
  814.         mov     [error_line],eax
  815.         mov     [error],invalid_value
  816.       zero_times:
  817.         call    skip_line
  818.         jmp     instruction_assembled
  819.  
  820. virtual_directive:
  821.         lods    byte [esi]
  822.         cmp     al,80h
  823.         jne     virtual_at_current
  824.         lods    byte [esi]
  825.         cmp     al,'('
  826.         jne     invalid_argument
  827.         cmp     byte [esi],'.'
  828.         je      invalid_value
  829.         call    get_address_value
  830.         mov     ebp,[address_symbol]
  831.         xor     ch,ch
  832.         or      bh,bh
  833.         jz      set_virtual
  834.         mov     ch,1
  835.         jmp     set_virtual
  836.       virtual_at_current:
  837.         dec     esi
  838.         mov     al,[labels_type]
  839.         mov     [value_type],al
  840.         mov     ebp,[org_symbol]
  841.         mov     eax,edi
  842.         xor     edx,edx
  843.         sub     eax,dword [org_origin]
  844.         sbb     edx,dword [org_origin+4]
  845.         mov     bx,word [org_registers]
  846.         mov     cx,word [org_registers+2]
  847.         xchg    bh,bl
  848.         xchg    ch,cl
  849.       set_virtual:
  850.         push    [org_registers]
  851.         mov     byte [org_registers],bh
  852.         mov     byte [org_registers+1],bl
  853.         mov     byte [org_registers+2],ch
  854.         mov     byte [org_registers+3],cl
  855.         call    allocate_structure_data
  856.         mov     word [ebx],virtual_directive-assembler
  857.         not     eax
  858.         not     edx
  859.         add     eax,1
  860.         adc     edx,0
  861.         add     eax,edi
  862.         adc     edx,0
  863.         xchg    dword [org_origin],eax
  864.         xchg    dword [org_origin+4],edx
  865.         mov     [ebx+10h],eax
  866.         mov     [ebx+14h],edx
  867.         pop     eax
  868.         mov     [ebx+18h],eax
  869.         mov     al,[virtual_data]
  870.         mov     [ebx+2],al
  871.         mov     al,[labels_type]
  872.         mov     [ebx+3],al
  873.         mov     eax,edi
  874.         xchg    eax,[org_start]
  875.         mov     [ebx+0Ch],eax
  876.         xchg    ebp,[org_symbol]
  877.         mov     [ebx+1Ch],ebp
  878.         mov     [ebx+8],edi
  879.         mov     eax,[current_line]
  880.         mov     [ebx+4],eax
  881.         or      [virtual_data],-1
  882.         mov     al,[value_type]
  883.         test    al,1
  884.         jnz     invalid_use_of_symbol
  885.         mov     [labels_type],al
  886.         jmp     instruction_assembled
  887.       allocate_structure_data:
  888.         mov     ebx,[structures_buffer]
  889.         sub     ebx,20h
  890.         cmp     ebx,[free_additional_memory]
  891.         jb      out_of_memory
  892.         mov     [structures_buffer],ebx
  893.         ret
  894.       find_structure_data:
  895.         mov     ebx,[structures_buffer]
  896.       scan_structures:
  897.         cmp     ebx,[additional_memory_end]
  898.         je      no_such_structure
  899.         cmp     ax,[ebx]
  900.         je      structure_data_found
  901.         add     ebx,20h
  902.         jmp     scan_structures
  903.       structure_data_found:
  904.         ret
  905.       no_such_structure:
  906.         stc
  907.         ret
  908.       end_virtual:
  909.         call    find_structure_data
  910.         jc      unexpected_instruction
  911.         mov     al,[ebx+2]
  912.         mov     [virtual_data],al
  913.         mov     al,[ebx+3]
  914.         mov     [labels_type],al
  915.         mov     eax,[ebx+10h]
  916.         mov     dword [org_origin],eax
  917.         mov     eax,[ebx+14h]
  918.         mov     dword [org_origin+4],eax
  919.         mov     eax,[ebx+18h]
  920.         mov     [org_registers],eax
  921.         mov     eax,[ebx+0Ch]
  922.         mov     [org_start],eax
  923.         mov     eax,[ebx+1Ch]
  924.         mov     [org_symbol],eax
  925.         mov     edi,[ebx+8]
  926.       remove_structure_data:
  927.         push    esi edi
  928.         mov     esi,[structures_buffer]
  929.         mov     ecx,ebx
  930.         sub     ecx,esi
  931.         lea     edi,[esi+20h]
  932.         mov     [structures_buffer],edi
  933.         shr     ecx,2
  934.         rep     movs dword [edi],[esi]
  935.         pop     edi esi
  936.         ret
  937. repeat_directive:
  938.         cmp     [prefixed_instruction],0
  939.         jne     unexpected_instruction
  940.         lods    byte [esi]
  941.         cmp     al,'('
  942.         jne     invalid_argument
  943.         cmp     byte [esi],'.'
  944.         je      invalid_value
  945.         call    get_dword_value
  946.         cmp     [next_pass_needed],0
  947.         jne     repeat_value_ok
  948.         cmp     [value_type],0
  949.         jne     invalid_use_of_symbol
  950.       repeat_value_ok:
  951.         cmp     eax,0
  952.         je      zero_repeat
  953.         jl      negative_repeat
  954.         call    allocate_structure_data
  955.         mov     word [ebx],repeat_directive-assembler
  956.         xchg    eax,[counter_limit]
  957.         mov     [ebx+10h],eax
  958.         mov     eax,1
  959.         xchg    eax,[counter]
  960.         mov     [ebx+14h],eax
  961.         mov     [ebx+8],esi
  962.         mov     eax,[current_line]
  963.         mov     [ebx+4],eax
  964.         jmp     instruction_assembled
  965.       end_repeat:
  966.         cmp     [prefixed_instruction],0
  967.         jne     unexpected_instruction
  968.         call    find_structure_data
  969.         jc      unexpected_instruction
  970.         mov     eax,[counter_limit]
  971.         inc     [counter]
  972.         cmp     [counter],eax
  973.         jbe     continue_repeating
  974.       stop_repeat:
  975.         mov     eax,[ebx+10h]
  976.         mov     [counter_limit],eax
  977.         mov     eax,[ebx+14h]
  978.         mov     [counter],eax
  979.         call    remove_structure_data
  980.         jmp     instruction_assembled
  981.       continue_repeating:
  982.         mov     esi,[ebx+8]
  983.         jmp     instruction_assembled
  984.       negative_repeat:
  985.         cmp     [error_line],0
  986.         jne     zero_repeat
  987.         mov     eax,[current_line]
  988.         mov     [error_line],eax
  989.         mov     [error],invalid_value
  990.       zero_repeat:
  991.         mov     al,[esi]
  992.         or      al,al
  993.         jz      missing_end_directive
  994.         cmp     al,0Fh
  995.         jne     extra_characters_on_line
  996.         call    find_end_repeat
  997.         jmp     instruction_assembled
  998.       find_end_repeat:
  999.         call    find_structure_end
  1000.         cmp     ax,repeat_directive-assembler
  1001.         jne     unexpected_instruction
  1002.         ret
  1003. while_directive:
  1004.         cmp     [prefixed_instruction],0
  1005.         jne     unexpected_instruction
  1006.         call    allocate_structure_data
  1007.         mov     word [ebx],while_directive-assembler
  1008.         mov     eax,1
  1009.         xchg    eax,[counter]
  1010.         mov     [ebx+10h],eax
  1011.         mov     [ebx+8],esi
  1012.         mov     eax,[current_line]
  1013.         mov     [ebx+4],eax
  1014.       do_while:
  1015.         push    ebx
  1016.         call    calculate_logical_expression
  1017.         or      al,al
  1018.         jnz     while_true
  1019.         mov     al,[esi]
  1020.         or      al,al
  1021.         jz      missing_end_directive
  1022.         cmp     al,0Fh
  1023.         jne     extra_characters_on_line
  1024.       stop_while:
  1025.         call    find_end_while
  1026.         pop     ebx
  1027.         mov     eax,[ebx+10h]
  1028.         mov     [counter],eax
  1029.         call    remove_structure_data
  1030.         jmp     instruction_assembled
  1031.       while_true:
  1032.         pop     ebx
  1033.         jmp     instruction_assembled
  1034.       end_while:
  1035.         cmp     [prefixed_instruction],0
  1036.         jne     unexpected_instruction
  1037.         call    find_structure_data
  1038.         jc      unexpected_instruction
  1039.         mov     eax,[ebx+4]
  1040.         mov     [current_line],eax
  1041.         inc     [counter]
  1042.         jz      too_many_repeats
  1043.         mov     esi,[ebx+8]
  1044.         jmp     do_while
  1045.       find_end_while:
  1046.         call    find_structure_end
  1047.         cmp     ax,while_directive-assembler
  1048.         jne     unexpected_instruction
  1049.         ret
  1050. if_directive:
  1051.         cmp     [prefixed_instruction],0
  1052.         jne     unexpected_instruction
  1053.         call    calculate_logical_expression
  1054.         mov     dl,al
  1055.         mov     al,[esi]
  1056.         or      al,al
  1057.         jz      missing_end_directive
  1058.         cmp     al,0Fh
  1059.         jne     extra_characters_on_line
  1060.         or      dl,dl
  1061.         jnz     if_true
  1062.         call    find_else
  1063.         jc      instruction_assembled
  1064.         mov     al,[esi]
  1065.         cmp     al,1
  1066.         jne     else_true
  1067.         cmp     word [esi+1],if_directive-assembler
  1068.         jne     else_true
  1069.         add     esi,4
  1070.         jmp     if_directive
  1071.       if_true:
  1072.         xor     al,al
  1073.       make_if_structure:
  1074.         call    allocate_structure_data
  1075.         mov     word [ebx],if_directive-assembler
  1076.         mov     byte [ebx+2],al
  1077.         mov     eax,[current_line]
  1078.         mov     [ebx+4],eax
  1079.         jmp     instruction_assembled
  1080.       else_true:
  1081.         or      al,al
  1082.         jz      missing_end_directive
  1083.         cmp     al,0Fh
  1084.         jne     extra_characters_on_line
  1085.         or      al,-1
  1086.         jmp     make_if_structure
  1087.       else_directive:
  1088.         cmp     [prefixed_instruction],0
  1089.         jne     unexpected_instruction
  1090.         mov     ax,if_directive-assembler
  1091.         call    find_structure_data
  1092.         jc      unexpected_instruction
  1093.         cmp     byte [ebx+2],0
  1094.         jne     unexpected_instruction
  1095.       found_else:
  1096.         mov     al,[esi]
  1097.         cmp     al,1
  1098.         jne     skip_else
  1099.         cmp     word [esi+1],if_directive-assembler
  1100.         jne     skip_else
  1101.         add     esi,4
  1102.         call    find_else
  1103.         jnc     found_else
  1104.         call    remove_structure_data
  1105.         jmp     instruction_assembled
  1106.       skip_else:
  1107.         or      al,al
  1108.         jz      missing_end_directive
  1109.         cmp     al,0Fh
  1110.         jne     extra_characters_on_line
  1111.         call    find_end_if
  1112.         call    remove_structure_data
  1113.         jmp     instruction_assembled
  1114.       end_if:
  1115.         cmp     [prefixed_instruction],0
  1116.         jne     unexpected_instruction
  1117.         call    find_structure_data
  1118.         jc      unexpected_instruction
  1119.         call    remove_structure_data
  1120.         jmp     instruction_assembled
  1121.       find_else:
  1122.         call    find_structure_end
  1123.         cmp     ax,else_directive-assembler
  1124.         je      else_found
  1125.         cmp     ax,if_directive-assembler
  1126.         jne     unexpected_instruction
  1127.         stc
  1128.         ret
  1129.       else_found:
  1130.         clc
  1131.         ret
  1132.       find_end_if:
  1133.         call    find_structure_end
  1134.         cmp     ax,if_directive-assembler
  1135.         jne     unexpected_instruction
  1136.         ret
  1137.       find_structure_end:
  1138.         push    [error_line]
  1139.         mov     eax,[current_line]
  1140.         mov     [error_line],eax
  1141.       find_end_directive:
  1142.         call    skip_line
  1143.         lods    byte [esi]
  1144.         cmp     al,0Fh
  1145.         jne     no_end_directive
  1146.         lods    dword [esi]
  1147.         mov     [current_line],eax
  1148.       skip_labels:
  1149.         cmp     byte [esi],2
  1150.         jne     labels_ok
  1151.         add     esi,6
  1152.         jmp     skip_labels
  1153.       labels_ok:
  1154.         cmp     byte [esi],1
  1155.         jne     find_end_directive
  1156.         mov     ax,[esi+1]
  1157.         cmp     ax,prefix_instruction-assembler
  1158.         je      find_end_directive
  1159.         add     esi,4
  1160.         cmp     ax,repeat_directive-assembler
  1161.         je      skip_repeat
  1162.         cmp     ax,while_directive-assembler
  1163.         je      skip_while
  1164.         cmp     ax,if_directive-assembler
  1165.         je      skip_if
  1166.         cmp     ax,else_directive-assembler
  1167.         je      structure_end
  1168.         cmp     ax,end_directive-assembler
  1169.         jne     find_end_directive
  1170.         cmp     byte [esi],1
  1171.         jne     find_end_directive
  1172.         mov     ax,[esi+1]
  1173.         add     esi,4
  1174.         cmp     ax,repeat_directive-assembler
  1175.         je      structure_end
  1176.         cmp     ax,while_directive-assembler
  1177.         je      structure_end
  1178.         cmp     ax,if_directive-assembler
  1179.         jne     find_end_directive
  1180.       structure_end:
  1181.         pop     [error_line]
  1182.         ret
  1183.       no_end_directive:
  1184.         mov     eax,[error_line]
  1185.         mov     [current_line],eax
  1186.         jmp     missing_end_directive
  1187.       skip_repeat:
  1188.         call    find_end_repeat
  1189.         jmp     find_end_directive
  1190.       skip_while:
  1191.         call    find_end_while
  1192.         jmp     find_end_directive
  1193.       skip_if:
  1194.         call    skip_if_block
  1195.         jmp     find_end_directive
  1196.       skip_if_block:
  1197.         call    find_else
  1198.         jc      if_block_skipped
  1199.         cmp     byte [esi],1
  1200.         jne     skip_after_else
  1201.         cmp     word [esi+1],if_directive-assembler
  1202.         jne     skip_after_else
  1203.         add     esi,4
  1204.         jmp     skip_if_block
  1205.       skip_after_else:
  1206.         call    find_end_if
  1207.       if_block_skipped:
  1208.         ret
  1209. end_directive:
  1210.         lods    byte [esi]
  1211.         cmp     al,1
  1212.         jne     invalid_argument
  1213.         lods    word [esi]
  1214.         inc     esi
  1215.         cmp     ax,virtual_directive-assembler
  1216.         je      end_virtual
  1217.         cmp     ax,repeat_directive-assembler
  1218.         je      end_repeat
  1219.         cmp     ax,while_directive-assembler
  1220.         je      end_while
  1221.         cmp     ax,if_directive-assembler
  1222.         je      end_if
  1223.         cmp     ax,data_directive-assembler
  1224.         je      end_data
  1225.         jmp     invalid_argument
  1226. break_directive:
  1227.         mov     ebx,[structures_buffer]
  1228.         mov     al,[esi]
  1229.         or      al,al
  1230.         jz      find_breakable_structure
  1231.         cmp     al,0Fh
  1232.         jne     extra_characters_on_line
  1233.       find_breakable_structure:
  1234.         cmp     ebx,[additional_memory_end]
  1235.         je      unexpected_instruction
  1236.         mov     ax,[ebx]
  1237.         cmp     ax,repeat_directive-assembler
  1238.         je      break_repeat
  1239.         cmp     ax,while_directive-assembler
  1240.         je      break_while
  1241.         cmp     ax,if_directive-assembler
  1242.         je      break_if
  1243.         add     ebx,20h
  1244.         jmp     find_breakable_structure
  1245.       break_if:
  1246.         push    [current_line]
  1247.         mov     eax,[ebx+4]
  1248.         mov     [current_line],eax
  1249.         call    remove_structure_data
  1250.         call    skip_if_block
  1251.         pop     [current_line]
  1252.         mov     ebx,[structures_buffer]
  1253.         jmp     find_breakable_structure
  1254.       break_repeat:
  1255.         push    ebx
  1256.         call    find_end_repeat
  1257.         pop     ebx
  1258.         jmp     stop_repeat
  1259.       break_while:
  1260.         push    ebx
  1261.         jmp     stop_while
  1262.  
  1263. data_bytes:
  1264.         call    define_data
  1265.         lods    byte [esi]
  1266.         cmp     al,'('
  1267.         je      get_byte
  1268.         cmp     al,'?'
  1269.         jne     invalid_argument
  1270.         mov     eax,edi
  1271.         mov     byte [edi],0
  1272.         inc     edi
  1273.         jmp     undefined_data
  1274.       get_byte:
  1275.         cmp     byte [esi],0
  1276.         je      get_string
  1277.         call    get_byte_value
  1278.         stos    byte [edi]
  1279.         ret
  1280.       get_string:
  1281.         inc     esi
  1282.         lods    dword [esi]
  1283.         mov     ecx,eax
  1284.         lea     eax,[edi+ecx]
  1285.         cmp     eax,[display_buffer]
  1286.         ja      out_of_memory
  1287.         rep     movs byte [edi],[esi]
  1288.         inc     esi
  1289.         ret
  1290.       undefined_data:
  1291.         cmp     [virtual_data],0
  1292.         je      mark_undefined_data
  1293.         ret
  1294.       mark_undefined_data:
  1295.         cmp     eax,[undefined_data_end]
  1296.         je      undefined_data_ok
  1297.         mov     [undefined_data_start],eax
  1298.       undefined_data_ok:
  1299.         mov     [undefined_data_end],edi
  1300.         ret
  1301.       define_data:
  1302.         cmp     edi,[display_buffer]
  1303.         jae     out_of_memory
  1304.         cmp     byte [esi],'('
  1305.         jne     simple_data_value
  1306.         mov     ebx,esi
  1307.         inc     esi
  1308.         call    skip_expression
  1309.         xchg    esi,ebx
  1310.         cmp     byte [ebx],81h
  1311.         jne     simple_data_value
  1312.         inc     esi
  1313.         call    get_dword_value
  1314.         cmp     [next_pass_needed],0
  1315.         jne     dup_value_ok
  1316.         cmp     [value_type],0
  1317.         jne     invalid_use_of_symbol
  1318.       dup_value_ok:
  1319.         inc     esi
  1320.         cmp     eax,0
  1321.         jg      dup_positive
  1322.         cmp     [error_line],0
  1323.         jne     dup_invalid
  1324.         mov     eax,[current_line]
  1325.         mov     [error_line],eax
  1326.         mov     [error],invalid_value
  1327.       dup_invalid:
  1328.         mov     eax,1
  1329.       dup_positive:
  1330.         cmp     byte [esi],'{'
  1331.         jne     duplicate_single_data_value
  1332.         inc     esi
  1333.       duplicate_data:
  1334.         push    eax esi
  1335.       duplicated_values:
  1336.         cmp     edi,[display_buffer]
  1337.         jae     out_of_memory
  1338.         call    near dword [esp+8]
  1339.         lods    byte [esi]
  1340.         cmp     al,','
  1341.         je      duplicated_values
  1342.         cmp     al,'}'
  1343.         jne     invalid_argument
  1344.         pop     ebx eax
  1345.         dec     eax
  1346.         jz      data_defined
  1347.         mov     esi,ebx
  1348.         jmp     duplicate_data
  1349.       duplicate_single_data_value:
  1350.         cmp     edi,[display_buffer]
  1351.         jae     out_of_memory
  1352.         push    eax esi
  1353.         call    near dword [esp+8]
  1354.         pop     ebx eax
  1355.         dec     eax
  1356.         jz      data_defined
  1357.         mov     esi,ebx
  1358.         jmp     duplicate_single_data_value
  1359.       simple_data_value:
  1360.         cmp     edi,[display_buffer]
  1361.         jae     out_of_memory
  1362.         call    near dword [esp]
  1363.       data_defined:
  1364.         lods    byte [esi]
  1365.         cmp     al,','
  1366.         je      define_data
  1367.         dec     esi
  1368.         add     esp,4
  1369.         jmp     instruction_assembled
  1370. data_unicode:
  1371.         or      [base_code],-1
  1372.         jmp     define_words
  1373. data_words:
  1374.         mov     [base_code],0
  1375.       define_words:
  1376.         call    define_data
  1377.         lods    byte [esi]
  1378.         cmp     al,'('
  1379.         je      get_word
  1380.         cmp     al,'?'
  1381.         jne     invalid_argument
  1382.         mov     eax,edi
  1383.         mov     word [edi],0
  1384.         scas    word [edi]
  1385.         jmp     undefined_data
  1386.         ret
  1387.       get_word:
  1388.         cmp     [base_code],0
  1389.         je      word_data_value
  1390.         cmp     byte [esi],0
  1391.         je      word_string
  1392.       word_data_value:
  1393.         call    get_word_value
  1394.         call    mark_relocation
  1395.         stos    word [edi]
  1396.         ret
  1397.       word_string:
  1398.         inc     esi
  1399.         lods    dword [esi]
  1400.         mov     ecx,eax
  1401.         jecxz   word_string_ok
  1402.         lea     eax,[edi+ecx*2]
  1403.         cmp     eax,[display_buffer]
  1404.         ja      out_of_memory
  1405.         xor     ah,ah
  1406.       copy_word_string:
  1407.         lods    byte [esi]
  1408.         stos    word [edi]
  1409.         loop    copy_word_string
  1410.       word_string_ok:
  1411.         inc     esi
  1412.         ret
  1413. data_dwords:
  1414.         call    define_data
  1415.         lods    byte [esi]
  1416.         cmp     al,'('
  1417.         je      get_dword
  1418.         cmp     al,'?'
  1419.         jne     invalid_argument
  1420.         mov     eax,edi
  1421.         mov     dword [edi],0
  1422.         scas    dword [edi]
  1423.         jmp     undefined_data
  1424.       get_dword:
  1425.         push    esi
  1426.         call    get_dword_value
  1427.         pop     ebx
  1428.         cmp     byte [esi],':'
  1429.         je      complex_dword
  1430.         call    mark_relocation
  1431.         stos    dword [edi]
  1432.         ret
  1433.       complex_dword:
  1434.         mov     esi,ebx
  1435.         cmp     byte [esi],'.'
  1436.         je      invalid_value
  1437.         call    get_word_value
  1438.         push    eax
  1439.         inc     esi
  1440.         lods    byte [esi]
  1441.         cmp     al,'('
  1442.         jne     invalid_operand
  1443.         mov     al,[value_type]
  1444.         push    eax
  1445.         cmp     byte [esi],'.'
  1446.         je      invalid_value
  1447.         call    get_word_value
  1448.         call    mark_relocation
  1449.         stos    word [edi]
  1450.         pop     eax
  1451.         mov     [value_type],al
  1452.         pop     eax
  1453.         call    mark_relocation
  1454.         stos    word [edi]
  1455.         ret
  1456. data_pwords:
  1457.         call    define_data
  1458.         lods    byte [esi]
  1459.         cmp     al,'('
  1460.         je      get_pword
  1461.         cmp     al,'?'
  1462.         jne     invalid_argument
  1463.         mov     eax,edi
  1464.         mov     dword [edi],0
  1465.         scas    dword [edi]
  1466.         mov     word [edi],0
  1467.         scas    word [edi]
  1468.         jmp     undefined_data
  1469.       get_pword:
  1470.         push    esi
  1471.         call    get_pword_value
  1472.         pop     ebx
  1473.         cmp     byte [esi],':'
  1474.         je      complex_pword
  1475.         call    mark_relocation
  1476.         stos    dword [edi]
  1477.         mov     ax,dx
  1478.         stos    word [edi]
  1479.         ret
  1480.       complex_pword:
  1481.         mov     esi,ebx
  1482.         cmp     byte [esi],'.'
  1483.         je      invalid_value
  1484.         call    get_word_value
  1485.         push    eax
  1486.         inc     esi
  1487.         lods    byte [esi]
  1488.         cmp     al,'('
  1489.         jne     invalid_operand
  1490.         mov     al,[value_type]
  1491.         push    eax
  1492.         cmp     byte [esi],'.'
  1493.         je      invalid_value
  1494.         call    get_dword_value
  1495.         call    mark_relocation
  1496.         stos    dword [edi]
  1497.         pop     eax
  1498.         mov     [value_type],al
  1499.         pop     eax
  1500.         call    mark_relocation
  1501.         stos    word [edi]
  1502.         ret
  1503. data_qwords:
  1504.         call    define_data
  1505.         lods    byte [esi]
  1506.         cmp     al,'('
  1507.         je      get_qword
  1508.         cmp     al,'?'
  1509.         jne     invalid_argument
  1510.         mov     eax,edi
  1511.         mov     dword [edi],0
  1512.         scas    dword [edi]
  1513.         mov     dword [edi],0
  1514.         scas    dword [edi]
  1515.         jmp     undefined_data
  1516.       get_qword:
  1517.         call    get_qword_value
  1518.         call    mark_relocation
  1519.         stos    dword [edi]
  1520.         mov     eax,edx
  1521.         stos    dword [edi]
  1522.         ret
  1523. data_twords:
  1524.         call    define_data
  1525.         lods    byte [esi]
  1526.         cmp     al,'('
  1527.         je      get_tword
  1528.         cmp     al,'?'
  1529.         jne     invalid_argument
  1530.         mov     eax,edi
  1531.         mov     dword [edi],0
  1532.         scas    dword [edi]
  1533.         mov     dword [edi],0
  1534.         scas    dword [edi]
  1535.         mov     word [edi],0
  1536.         scas    word [edi]
  1537.         jmp     undefined_data
  1538.       get_tword:
  1539.         cmp     byte [esi],'.'
  1540.         jne     complex_tword
  1541.         inc     esi
  1542.         cmp     word [esi+8],8000h
  1543.         je      fp_zero_tword
  1544.         mov     eax,[esi]
  1545.         stos    dword [edi]
  1546.         mov     eax,[esi+4]
  1547.         stos    dword [edi]
  1548.         mov     ax,[esi+8]
  1549.         add     ax,3FFFh
  1550.         cmp     ax,8000h
  1551.         jae     value_out_of_range
  1552.         mov     bl,[esi+11]
  1553.         shl     bx,15
  1554.         or      ax,bx
  1555.         stos    word [edi]
  1556.         add     esi,13
  1557.         ret
  1558.       fp_zero_tword:
  1559.         xor     eax,eax
  1560.         stos    dword [edi]
  1561.         stos    dword [edi]
  1562.         mov     al,[esi+11]
  1563.         shl     ax,15
  1564.         stos    word [edi]
  1565.         add     esi,13
  1566.         ret
  1567.       complex_tword:
  1568.         call    get_word_value
  1569.         push    eax
  1570.         inc     esi
  1571.         lods    byte [esi]
  1572.         cmp     al,'('
  1573.         jne     invalid_operand
  1574.         mov     al,[value_type]
  1575.         push    eax
  1576.         cmp     byte [esi],'.'
  1577.         je      invalid_value
  1578.         call    get_qword_value
  1579.         call    mark_relocation
  1580.         stos    dword [edi]
  1581.         mov     eax,edx
  1582.         stos    dword [edi]
  1583.         pop     eax
  1584.         mov     [value_type],al
  1585.         pop     eax
  1586.         call    mark_relocation
  1587.         stos    word [edi]
  1588.         ret
  1589. data_file:
  1590.         lods    word [esi]
  1591.         cmp     ax,'('
  1592.         jne     invalid_argument
  1593.         add     esi,4
  1594.         call    open_binary_file
  1595.         mov     eax,[esi-4]
  1596.         lea     esi,[esi+eax+1]
  1597.         mov     al,2
  1598.         xor     edx,edx
  1599.         call    lseek
  1600.         push    eax
  1601.         xor     edx,edx
  1602.         cmp     byte [esi],':'
  1603.         jne     position_ok
  1604.         inc     esi
  1605.         cmp     byte [esi],'('
  1606.         jne     invalid_argument
  1607.         inc     esi
  1608.         cmp     byte [esi],'.'
  1609.         je      invalid_value
  1610.         push    ebx
  1611.         call    get_dword_value
  1612.         pop     ebx
  1613.         mov     edx,eax
  1614.         sub     [esp],edx
  1615.       position_ok:
  1616.         cmp     byte [esi],','
  1617.         jne     size_ok
  1618.         inc     esi
  1619.         cmp     byte [esi],'('
  1620.         jne     invalid_argument
  1621.         inc     esi
  1622.         cmp     byte [esi],'.'
  1623.         je      invalid_value
  1624.         push    ebx edx
  1625.         call    get_dword_value
  1626.         pop     edx ebx
  1627.         mov     [esp],eax
  1628.       size_ok:
  1629.         xor     al,al
  1630.         call    lseek
  1631.         pop     ecx
  1632.         mov     edx,edi
  1633.         add     edi,ecx
  1634.         jc      out_of_memory
  1635.         cmp     edi,[display_buffer]
  1636.         ja      out_of_memory
  1637.         call    read
  1638.         jc      error_reading_file
  1639.         call    close
  1640.         lods    byte [esi]
  1641.         cmp     al,','
  1642.         je      data_file
  1643.         dec     esi
  1644.         jmp     instruction_assembled
  1645.       open_binary_file:
  1646.         push    esi
  1647.         push    edi
  1648.         mov     esi,[current_line]
  1649.         mov     esi,[esi]
  1650.       get_current_path:
  1651.         lodsb
  1652.         stosb
  1653.         or      al,al
  1654.         jnz     get_current_path
  1655.       cut_current_path:
  1656.         cmp     edi,[esp]
  1657.         je      current_path_ok
  1658.         cmp     byte [edi-1],'\'
  1659.         je      current_path_ok
  1660.         cmp     byte [edi-1],'/'
  1661.         je      current_path_ok
  1662.         dec     edi
  1663.         jmp     cut_current_path
  1664.       current_path_ok:
  1665.         mov     esi,[esp+4]
  1666.         call    preprocess_path
  1667.         pop     edx
  1668.         mov     esi,edx
  1669.         call    open
  1670.         jnc     file_opened
  1671.         mov     edi,esi
  1672.         mov     esi,[esp]
  1673.         push    edi
  1674.         call    preprocess_path
  1675.         pop     edx
  1676.         mov     esi,edx
  1677.         call    open
  1678.         jc      file_not_found
  1679.       file_opened:
  1680.         mov     edi,esi
  1681.         pop     esi
  1682.         ret
  1683. reserve_bytes:
  1684.         lods    byte [esi]
  1685.         cmp     al,'('
  1686.         jne     invalid_argument
  1687.         cmp     byte [esi],'.'
  1688.         je      invalid_value
  1689.         call    get_dword_value
  1690.         cmp     [next_pass_needed],0
  1691.         jne     rb_value_ok
  1692.         cmp     [value_type],0
  1693.         jne     invalid_use_of_symbol
  1694.       rb_value_ok:
  1695.         cmp     eax,0
  1696.         jl      reserve_negative
  1697.         mov     ecx,eax
  1698.         mov     edx,ecx
  1699.         add     edx,edi
  1700.         jc      out_of_memory
  1701.         cmp     edx,[display_buffer]
  1702.         ja      out_of_memory
  1703.         push    edi
  1704.         cmp     [next_pass_needed],0
  1705.         je      zero_bytes
  1706.         add     edi,ecx
  1707.         jmp     reserved_data
  1708.       zero_bytes:
  1709.         xor     eax,eax
  1710.         shr     ecx,1
  1711.         jnc     bytes_stosb_ok
  1712.         stos    byte [edi]
  1713.       bytes_stosb_ok:
  1714.         shr     ecx,1
  1715.         jnc     bytes_stosw_ok
  1716.         stos    word [edi]
  1717.       bytes_stosw_ok:
  1718.         rep     stos dword [edi]
  1719.       reserved_data:
  1720.         pop     eax
  1721.         call    undefined_data
  1722.         jmp     instruction_assembled
  1723.       reserve_negative:
  1724.         cmp     [error_line],0
  1725.         jne     instruction_assembled
  1726.         mov     eax,[current_line]
  1727.         mov     [error_line],eax
  1728.         mov     [error],invalid_value
  1729.         jmp     instruction_assembled
  1730. reserve_words:
  1731.         lods    byte [esi]
  1732.         cmp     al,'('
  1733.         jne     invalid_argument
  1734.         cmp     byte [esi],'.'
  1735.         je      invalid_value
  1736.         call    get_dword_value
  1737.         cmp     [next_pass_needed],0
  1738.         jne     rw_value_ok
  1739.         cmp     [value_type],0
  1740.         jne     invalid_use_of_symbol
  1741.       rw_value_ok:
  1742.         cmp     eax,0
  1743.         jl      reserve_negative
  1744.         mov     ecx,eax
  1745.         mov     edx,ecx
  1746.         shl     edx,1
  1747.         jc      out_of_memory
  1748.         add     edx,edi
  1749.         jc      out_of_memory
  1750.         cmp     edx,[display_buffer]
  1751.         ja      out_of_memory
  1752.         push    edi
  1753.         cmp     [next_pass_needed],0
  1754.         je      zero_words
  1755.         lea     edi,[edi+ecx*2]
  1756.         jmp     reserved_data
  1757.       zero_words:
  1758.         xor     eax,eax
  1759.         shr     ecx,1
  1760.         jnc     words_stosw_ok
  1761.         stos    word [edi]
  1762.       words_stosw_ok:
  1763.         rep     stos dword [edi]
  1764.         jmp     reserved_data
  1765. reserve_dwords:
  1766.         lods    byte [esi]
  1767.         cmp     al,'('
  1768.         jne     invalid_argument
  1769.         cmp     byte [esi],'.'
  1770.         je      invalid_value
  1771.         call    get_dword_value
  1772.         cmp     [next_pass_needed],0
  1773.         jne     rd_value_ok
  1774.         cmp     [value_type],0
  1775.         jne     invalid_use_of_symbol
  1776.       rd_value_ok:
  1777.         cmp     eax,0
  1778.         jl      reserve_negative
  1779.         mov     ecx,eax
  1780.         mov     edx,ecx
  1781.         shl     edx,1
  1782.         jc      out_of_memory
  1783.         shl     edx,1
  1784.         jc      out_of_memory
  1785.         add     edx,edi
  1786.         jc      out_of_memory
  1787.         cmp     edx,[display_buffer]
  1788.         ja      out_of_memory
  1789.         push    edi
  1790.         cmp     [next_pass_needed],0
  1791.         je      zero_dwords
  1792.         lea     edi,[edi+ecx*4]
  1793.         jmp     reserved_data
  1794.       zero_dwords:
  1795.         xor     eax,eax
  1796.         rep     stos dword [edi]
  1797.         jmp     reserved_data
  1798. reserve_pwords:
  1799.         lods    byte [esi]
  1800.         cmp     al,'('
  1801.         jne     invalid_argument
  1802.         cmp     byte [esi],'.'
  1803.         je      invalid_value
  1804.         call    get_dword_value
  1805.         cmp     [next_pass_needed],0
  1806.         jne     rp_value_ok
  1807.         cmp     [value_type],0
  1808.         jne     invalid_use_of_symbol
  1809.       rp_value_ok:
  1810.         cmp     eax,0
  1811.         jl      reserve_negative
  1812.         mov     ecx,eax
  1813.         shl     ecx,1
  1814.         jc      out_of_memory
  1815.         add     ecx,eax
  1816.         mov     edx,ecx
  1817.         shl     edx,1
  1818.         jc      out_of_memory
  1819.         add     edx,edi
  1820.         jc      out_of_memory
  1821.         cmp     edx,[display_buffer]
  1822.         ja      out_of_memory
  1823.         push    edi
  1824.         cmp     [next_pass_needed],0
  1825.         je      zero_words
  1826.         lea     edi,[edi+ecx*2]
  1827.         jmp     reserved_data
  1828. reserve_qwords:
  1829.         lods    byte [esi]
  1830.         cmp     al,'('
  1831.         jne     invalid_argument
  1832.         cmp     byte [esi],'.'
  1833.         je      invalid_value
  1834.         call    get_dword_value
  1835.         cmp     [next_pass_needed],0
  1836.         jne     rq_value_ok
  1837.         cmp     [value_type],0
  1838.         jne     invalid_use_of_symbol
  1839.       rq_value_ok:
  1840.         cmp     eax,0
  1841.         jl      reserve_negative
  1842.         mov     ecx,eax
  1843.         shl     ecx,1
  1844.         jc      out_of_memory
  1845.         mov     edx,ecx
  1846.         shl     edx,1
  1847.         jc      out_of_memory
  1848.         shl     edx,1
  1849.         jc      out_of_memory
  1850.         add     edx,edi
  1851.         jc      out_of_memory
  1852.         cmp     edx,[display_buffer]
  1853.         ja      out_of_memory
  1854.         push    edi
  1855.         cmp     [next_pass_needed],0
  1856.         je      zero_dwords
  1857.         lea     edi,[edi+ecx*4]
  1858.         jmp     reserved_data
  1859. reserve_twords:
  1860.         lods    byte [esi]
  1861.         cmp     al,'('
  1862.         jne     invalid_argument
  1863.         cmp     byte [esi],'.'
  1864.         je      invalid_value
  1865.         call    get_dword_value
  1866.         cmp     [next_pass_needed],0
  1867.         jne     rt_value_ok
  1868.         cmp     [value_type],0
  1869.         jne     invalid_use_of_symbol
  1870.       rt_value_ok:
  1871.         cmp     eax,0
  1872.         jl      reserve_negative
  1873.         mov     ecx,eax
  1874.         shl     ecx,2
  1875.         jc      out_of_memory
  1876.         add     ecx,eax
  1877.         mov     edx,ecx
  1878.         shl     edx,1
  1879.         jc      out_of_memory
  1880.         add     edx,edi
  1881.         jc      out_of_memory
  1882.         cmp     edx,[display_buffer]
  1883.         ja      out_of_memory
  1884.         push    edi
  1885.         cmp     [next_pass_needed],0
  1886.         je      zero_words
  1887.         lea     edi,[edi+ecx*2]
  1888.         jmp     reserved_data
  1889. align_directive:
  1890.         lods    byte [esi]
  1891.         cmp     al,'('
  1892.         jne     invalid_argument
  1893.         cmp     byte [esi],'.'
  1894.         je      invalid_value
  1895.         call    get_dword_value
  1896.         cmp     [value_type],0
  1897.         jne     invalid_use_of_symbol
  1898.         mov     edx,eax
  1899.         dec     edx
  1900.         test    eax,edx
  1901.         jnz     negative_times
  1902.         or      eax,eax
  1903.         jz      negative_times
  1904.         cmp     eax,1
  1905.         je      instruction_assembled
  1906.         mov     ecx,edi
  1907.         sub     ecx,dword [org_origin]
  1908.         cmp     [org_registers],0
  1909.         jne     section_not_aligned_enough
  1910.         cmp     [labels_type],0
  1911.         je      make_alignment
  1912.         cmp     [output_format],3
  1913.         je      pe_alignment
  1914.         mov     ebx,[org_symbol]
  1915.         cmp     byte [ebx],0
  1916.         jne     section_not_aligned_enough
  1917.         cmp     eax,[ebx+10h]
  1918.         jbe     make_alignment
  1919.         jmp     section_not_aligned_enough
  1920.       pe_alignment:
  1921.         cmp     eax,1000h
  1922.         ja      section_not_aligned_enough
  1923.       make_alignment:
  1924.         dec     eax
  1925.         and     ecx,eax
  1926.         jz      instruction_assembled
  1927.         neg     ecx
  1928.         add     ecx,eax
  1929.         inc     ecx
  1930.         mov     edx,ecx
  1931.         add     edx,edi
  1932.         jc      out_of_memory
  1933.         cmp     edx,[display_buffer]
  1934.         ja      out_of_memory
  1935.         push    edi
  1936.         cmp     [next_pass_needed],0
  1937.         je      nops
  1938.         add     edi,ecx
  1939.         jmp     reserved_data
  1940.       nops:
  1941.         mov     eax,90909090h
  1942.         shr     ecx,1
  1943.         jnc     nops_stosb_ok
  1944.         stos    byte [edi]
  1945.       nops_stosb_ok:
  1946.         shr     ecx,1
  1947.         jnc     nops_stosw_ok
  1948.         stos    word [edi]
  1949.       nops_stosw_ok:
  1950.         rep     stos dword [edi]
  1951.         jmp     reserved_data
  1952.