title: Delphi XE2 assembly
body: <p>I have the following function that works in Delphi 2006, but under Delphi XE2 it gives either an access violation error or a privileged instruction error when processing <code>RET</code>.</p>
  
  <pre><code>function Q_TrimChar(const S: string; Ch: Char): string;
  asm
          PUSH    ESI
          MOV     ESI,ECX
          TEST    EAX,EAX
          JE      @@qt
          MOV     ECX,[EAX-4]
          TEST    ECX,ECX
          JE      @@qt
          PUSH    EBX
          PUSH    EDI
          MOV     EBX,EAX
          MOV     EDI,EDX
          XOR     EDX,EDX
          MOV     EAX,ESI
          CALL    System.@LStrFromPCharLen
          MOV     EDX,EDI
          MOV     ECX,[EBX-4]
  @@lp1:  CMP     DL,BYTE PTR [EBX]
          JNE     @@ex1
          INC     EBX
          DEC     ECX
          JNE     @@lp1
          MOV     EDX,[ESI]
          JMP     @@wq
  @@ex1:  DEC     ECX
  @@lp2:  CMP     DL,BYTE PTR [EBX+ECX]
          JNE     @@ex2
          DEC     ECX
          JMP     @@lp2
  @@ex2:  MOV     EDI,[ESI]
          LEA     EDX,[EDI+ECX+1]
  @@lp3:  MOV     AL,BYTE PTR [EBX+ECX]
          MOV     BYTE PTR [EDI+ECX],AL
          DEC     ECX
          JNS     @@lp3
  @@wq:   MOV     EAX,[ESI]
          MOV     BYTE PTR [EDX],0
          SUB     EDX,EAX
          MOV     [EAX-4],EDX
          POP     EDI
          POP     EBX
          POP     ESI
          RET
  @@qt:   MOV     EAX,ESI
          CALL    System.@LStrClr
          POP     ESI
  end;
  </code></pre>
  
  <p>I don't know assembly very well. What is the problem?</p>