Calling conventions



The Windows API uses the stdcall convention where the called procedure
is responsible for cleaning up the stack. In NASM I would use a macro
(one of the few places where I would) like so:

%macro scall 2-*
%define _func %1
%rep %0 - 1
%rotate -1
push %1
%endrep
call _func
%endmacro

In RosAsm, I would end up using this:

[push | push #1 | #+1]
[call | push #L>2 | call #1]

Now for the problem. I believe that the functions supported by
msvcrt.dll use the cdecl calling convention instead of the stdcall
calling convention where the caller is repsonsible for cleaning up the
stack. In RosAsm, I'm not entirely sure how much damage I'm doing
because this:

call 'msvcrt.printf',fmt

works just as well as this:

call 'msvcrt.printf',fmt | add esp,4

In NASM, I would use a different macro to handle the cdecl calling
convention such that it adds the right amount to esp to clean up the
stack after the call:

%macro scall 2-*
%define _func %1
%assign __params %0 - 1
%assign __params __params * 4
%rep %0 - 1
%rotate -1
push %1
%endrep
call _func
add esp,__params
%endmacro

In RosAsm, I haven't yet figured out how to get a macro to do that. My
question is this: Am I trashing the stack by using an stdcall calling
convention when a cdecl calling convention is expected by the functions
I'm calling?

.



Relevant Pages

  • Re: hpux11 PA-RISC ABI Specification
    ... Yes, it does say that, but the convention did change. ... Copy" cache control hint that we wanted to use when storing to the stack ... whether any 16-byte stack frames were present in the code, ...
    (comp.arch)
  • Re: back online again...
    ... really "acceptable") convention. ... stack machine, but the design ... target with my compiler (may need a different name for this though, ... most of this code is not likely to ever go to object files anyways... ...
    (alt.lang.asm)
  • RE: You cant go to the specified record
    ... I would like to encourage you to use some type of naming ... It doesn't have to be any formal naming convention that may be ... like your account macro named macAcctProjectCodeAdd. ... rename objects but it will search all of your code, SQL statements, ...
    (microsoft.public.access.formscoding)
  • Re: Calling a function when the number of parameters isnt known till runtime
    ... The problem is that you have to decide on a convention for determining ... especially on x86 calling ... the FPU stack, and then overflow goes into the hardware stack. ... convention for passing in structs that are smaller than 64 bits. ...
    (comp.lang.c)
  • Re: calling convention stdcalll and cdecl call
    ... parameters from the stack. ... It uses cdecl convention, where the ... How would your hypothetical stdcall printf know to remove 12 bytes worth ...
    (microsoft.public.vc.language)