Question about x86 delegate calling convention
Jarrett Billingsley
kb3ctd2 at yahoo.com
Wed Jun 28 08:08:10 PDT 2006
I was stepping through some assembly when debugging one of my programs, and
I noticed something a bit odd about how delegates were called.
Delegates consist basically of two things: a context pointer (either 'this'
for class members or the outer function's frame pointer for nested
functions), and the address of the actual code. This is how D seems to call
delegates:
EAX = context ptr;
EDX = code address;
EBX = context ptr;
EDX();
Inside the delegate, only the EAX context pointer is ever used. 'this' is
also passed in EAX when calling class methods directly (a.method()).
My question is: why is EBX filled with the context pointer? It's never used
in the delegate; in fact, if the delegate has some complex code, and the
codegen needs another register, it will preserve EBX (pushing it) before
using it.
This happens even in release mode.
Is this a vestige of some older calling convention for delegates?
I also want to know this because I'm working on a (blatantly non-portable)
method of dynamically calling functions at run-time (for fun).
More information about the Digitalmars-d
mailing list