Subversion Repositories Kolibri OS

Rev

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

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