1. Pascal calling convention

While playing arround with some Delphi DLL's I noticed that Euphoria supports
the "pascal" calling convention as well. I thought some people might want to
know how to support the "pascal" calling methed in Euphoria so I've included
some info for those who are interrested.

Euphoria's standard c_proc()/c_func() method pushes the values onto the stack
from "right to left".  The only defference with the pascal convention is that
the values are pushed onto the stack from "left to right".

The example demonstrates the SAME C routine using the stdcel and pascal call
The file "test.dll" contains the same procedure declared twice. one with the 
"stdcel" method and the other declared as "pascal" method.

atom proc1 proc1=define_c_proc("test1.dll","proc1",{C_CHAR,C_UINT,C_DOUBLE}) --
stdcel convention --
atom proc2 proc2=define_c_func("test2.dll","proc2",{C_DOUBLE,C_UINT,C_CHAR}) --
pascal convention --

-- assumes proc enters with --
-- push ebp
-- mov ebp,esp 

-- stdcel stack --    -- values are pushed from back to front.
"[ebp+16]" -- C_DOUBLE
"[ebp+12]" -- C_UINT
"[ebp+08]" -- C_CHAR
"[ebp+04]" -- stack pointer
"[ebp+00]" -- return address

-- pascal stack --    -- values are pushed from front to back.
"[ebp+18]" -- C_CHAR
"[ebp+14]" -- C_UINT
"[ebp+08]" -- C_DOUBLE
"[ebp+04]" -- stack pointer
"[ebp+00]" -- return address

so.. to conclude. to call a delphi routine that's declared with the pascal
method just reverse the paramter list passed to define_c_proc().  So for a
pascal procedure routine that expects "a" then "b" followd by "c", we pass
"c" then "b" followd by "a" to the define_c_proc() paramter list.

I hope this explains how to use the pascal convention.  I'm not to good at
explaining theese things.

new topic     » topic index » view message » categorize

2. Re: Pascal calling convention

Hayden McKay wrote:
> 
> Euphoria's standard c_proc()/c_func() method pushes the values onto the stack
> from "right to left".  The only defference with the pascal convention is that
> the values are pushed onto the stack from "left to right".
> I hope this explains how to use the pascal convention.  I'm not to good at
> explaining theese things.
> 

Hayden:

   You are 2 years too late.
   See the following:

http://www.listfilter.com/cgi-bin/esearch.exu?fromMonth=B&fromYear=8&toMonth=B&toYear=8&postedBy=xotron&keywords=pascal

Bernie

My files in archive:
w32engin.ew mixedlib.e eu_engin.e win32eru.ew

Can be downloaded here:
http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan

new topic     » goto parent     » topic index » view message » categorize

3. Re: Pascal calling convention

Hayden McKay wrote:
> 
> While playing arround with some Delphi DLL's I noticed that Euphoria supports
> the "pascal" calling convention as well. I thought some people might want to
> know how to support the "pascal" calling methed in Euphoria so I've included
> some info for those who are interrested.
> 
> Euphoria's standard c_proc()/c_func() method pushes the values onto the stack
> from "right to left".  The only defference with the pascal convention is that
> the values are pushed onto the stack from "left to right".
> 
> The example demonstrates the SAME C routine using the stdcel and pascal call
> The file "test.dll" contains the same procedure declared twice. one with the 
> "stdcel" method and the other declared as "pascal" method.
> 

There is more to calling convention than the push order here more information
about it extracted from the folowing page: 

<a
href="http://info.borland.com/techpubs/delphi/delphi5/oplg/procfunc.html#8406">calling
convention</a>

Calling conventions determine the order in which parameters are passed to the
 routine. They also affect the removal of parameters from the stack, the use of
 registers for passing parameters, and error and exception handling. The default
 calling convention is register.

* The register and pascal conventions pass parameters from left to right;
    that is, the leftmost parameter is evaluated and passed first and the rightmost
    parameter is evaluated and passed last. The cdecl, stdcall, and safecall
    conventions pass parameters from right to left.
* For all conventions except cdecl, the procedure or function removes
    parameters from the stack upon returning. With the cdecl convention, the caller
    removes parameters from the stack when the call returns.
* The register convention uses up to three CPU registers to pass parameters,
    while the other conventions pass all parameters on the stack.
    * The safecall convention implements COM error and exception handling. 

regards,
Jacques D.

new topic     » goto parent     » topic index » view message » categorize

4. Re: Pascal calling convention

I only needed to use the pascal convention while playing arround with the
"vesa audio interface specification" with my 16-bit sound blaster.  there
is a function call that returns some pointers to some routines that reside
on the sound board that use the pascal calling convention.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu