Delphi Assembly Function Returning a Long String

后端 未结 2 1016
天命终不由人
天命终不由人 2021-01-15 13:26

I am trying to learn inline assembly programming in Delphi, and to this end I have found this article highly helpful.

Now I wish to write an assembly function return

相关标签:
2条回答
  • 2021-01-15 13:41

    With the excellent aid of A.Bouchez, I managed to correct my own code, employing LStrSetLength:

    function myfunc: AnsiString;
    asm
    
      push eax
    
      // eax = @result
      mov edx, 3
      mov ecx, 1252
      call System.@LStrSetLength
    
      pop eax
    
      mov ecx, [eax]
    
      mov [ecx], 'A'
      mov [ecx] + 1, 'B'
      mov [ecx] + 2, 'C'
    
    end;
    
    0 讨论(0)
  • 2021-01-15 13:51

    You have to use some kind of:

    function myfunc: AnsiString;
    asm
      push eax // save @result
      call system.@LStrClr
      mov    eax,3                 {Length}
    {$ifdef UNICODE}
      mov    edx,1252 // code page for Delphi 2009/2010
    {$endif}
      call   system.@NewAnsiString
      pop edx
      mov [edx],eax
      mov [eax],$303132
    end;
    

    It will return a '210' string...

    And it's always a good idea of putting a {$ifdef UNICODE} block to have your code compatible with version of Delphi prior to 2009.

    0 讨论(0)
提交回复
热议问题