Discussion:
Where's the function result?
(too old to reply)
Eli Gottlieb
2006-12-15 20:07:20 UTC
Permalink
I'm calling some code built with the Pascal calling convention modifier
from assembly, and I need to know where the function result will be
stored. Where will an integral result be stored? Where will a result
larger than an integer go?

Basically, I have code:

asm
call Function
end;

And I need to know where the result of Function() will be on the stack.
Can anyone tell me, or should I just disassemble a program?
p***@pgrahams.com
2006-12-17 19:36:50 UTC
Permalink
Eli Gottlieb <***@gmail.com> wrote:

|I'm calling some code built with the Pascal calling convention modifier
|from assembly, and I need to know where the function result will be
|stored.

Quoted from Delphi 6 help files:

The following conventions are used for returning function result
values.

Ordinal results are returned, when possible, in a CPU register. Bytes
are returned in AL, words are returned in AX, and double-words are
returned in EAX.
Real results are returned in the floating-point coprocessor’s
top-of-stack register (ST(0)). For function results of type Currency,
the value in ST(0) is scaled by 10000. For example, the Currency value
1.234 is returned in ST(0) as 12340.
For a string, dynamic array, method pointer, variant, or Int64
result, the effects are the same as if the function result were
declared as an additional var parameter following the declared
parameters. In other words, the caller passes an additional 32-bit
pointer that points to a variable in which to return the function
result.

Pointer, class, class-reference, and procedure-pointer results are
returned in EAX.
For static-array, record, and set results, if the value
occupies one byte it is returned in AL; if the value occupies two
bytes it is returned in AX; and if the value occupies four bytes it is
returned in EAX. Otherwise, the result is returned in an additional
var parameter that is passed to the function after the declared
parameters.

End Quote.

In addition, I believe that a quad word result is returned in EDX:EAX.

Phil

Continue reading on narkive:
Loading...