Subversion Repositories Kolibri OS

Rev

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