Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 593735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:52:38+00:00 2026-05-13T15:52:38+00:00

I have this code below, and I want to translate it to ASM, to

  • 0

I have this code below, and I want to translate it to ASM, to use in Delphi too.

var
    FunctionAddressList: Array of Integer;

type TFunction = function(parameter: Integer): Integer; cdecl;

function Function(parameter: Integer): Integer;
var
    ExternFunction: TFunction;
begin
    ExternFunction := TFunction(FunctionAddressList[5]);
    Result := ExternFunction(parameter);
end;

It works normaly, but when I try its Assembly version:

function Function(parameter: Integer): Integer; cdecl;
asm
  mov eax, FunctionAddressList
  jmp dword ptr [eax + 5 * 4]
end;

It is supposed to work, because, in C++ it works in both ways:

void *FunctionAddressList;

_declspec(naked) int Function(int parameter)
{
    _asm mov eax, FunctionAddressList;
    _asm jmp dword ptr [eax + 5 * 4];
}

typedef int (*TFunction)(int parameter);
int Function(int parameter)
{
    TFunction ExternFunction = ((TFunction *)FunctionAddressList)[5];
    return ExternFunction(parameter);
}

But it doesn’t work in Delphi.

In the Assembly version, it multiplies the array to 4, because it’s the offset size between each element of the array, so both versions are equivalent.

So, I want to know why it doesn’t work with Delphi. In Delphi, the offset size between Integer values in a array is different than C++?

I’ve already tried many offsets, as 1, 2, 4, 6, 8, etc. And many types of Array (Array of Pointer; only Pointer; Array of Integer, etc), and I’ve tried many calling conventions, and cdecl was the only that worked with the non-asm version, but with ASM, all the tests didn’t work.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:52:39+00:00Added an answer on May 13, 2026 at 3:52 pm

    First test app to reproduce error:

    var
      FunctionAddressList: Array of Integer;
    
    function Bar(parameter: Integer): Integer; cdecl;
    begin
      ShowMessage('Bar '+IntToStr(parameter));
    end;
    
    function Foo(parameter: Integer): Integer; cdecl;
    asm
      mov eax, FunctionAddressList
      jmp dword ptr [eax + 5 * 4]
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      SetLength(FunctionAddressList, 6);
      FunctionAddressList[5]:= Integer(@Bar);
      Foo(25);
    end;
    

    The Bar address is defined correctly, but the problem is that Delphi compiler generates prologue and epilog for Foo, so real Foo code is

    0046CD30 55               push ebp
    0046CD31 8BEC             mov ebp,esp
    Unit1.pas.46:             mov eax, FunctionAddressList
    Unit1.pas.47:             jmp dword ptr [eax + 5 * 4]
    0046CD3B 5D               pop ebp
    0046CD3C C3               ret
    

    As a result the stack is corrupted, the parameter is wrong and Bar return address is wrong. If you still want to do the trick, use

    function Foo(parameter: Integer): Integer; cdecl;
    asm
      pop ebp
      mov eax, FunctionAddressList
      jmp dword ptr [eax + 5 * 4]
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this snippet of code below. I want to pass the value of
I have the code below and I want to loop this every 5 seconds.
I have this code below: $insert = array(); for ($i = 1, $n =
I have this below code and it work fine header (content-type: text/xml); $xml =
I have this perl code below, basically want to loop through these 2 files.
I have this below code and i want to have a fadeIn effect to
I have this code below and want it to show the progress of a
I have this code below and want it to show the progress of a
I have this code below. As you can see I am passing two variables
I have this javascript code below that uses jquery, it is suppoed to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.