www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Register calling convention for asm functions...

reply "Chris Warwick" <sp m.me.not> writes:
What do i need to do to get register calling convention for asm? I've found 
extern(C) for cdecl calling convention, and i have seen mention of the 
'naked' keyword but cant work out where it goes... im not even sure if it 
does cause register calling convention or just causes the compiler to omit 
entry and exit code.

I assume it must be possible to write asm functions that take arguments in 
the eax,ecx,edx registers?

thanks,

cw 
Mar 11 2007
next sibling parent reply Daniel Keep <daniel.keep.lists+dm gmail.com> writes:
Chris Warwick Wrote:

 What do i need to do to get register calling convention for asm? I've found 
 extern(C) for cdecl calling convention, and i have seen mention of the 
 'naked' keyword but cant work out where it goes... im not even sure if it 
 does cause register calling convention or just causes the compiler to omit 
 entry and exit code.
 
 I assume it must be possible to write asm functions that take arguments in 
 the eax,ecx,edx registers?
 
 thanks,
 
 cw 

You put 'naked' at the top of a function body, and it causes the compiler to omit the function prelude and prologue. So, for example: void breakpoint() { naked; asm { int 3; } } Compiles literally as INT 0x3 As for arguments in registers, you can't do that. If you want to have a function that you pass arguments to via registers, then you need to "call" it using asm. I'd write you an example, but I'm typing this from a Mac at uni and, well, my assembler ain't that crash-hot :3 -- Daniel
Mar 11 2007
parent "Chris Warwick" <sp m.me.not> writes:
"Daniel Keep" <daniel.keep.lists+dm gmail.com> wrote in message 
news:et2kt5$2g7c$1 digitalmars.com...
 Chris Warwick Wrote:

 What do i need to do to get register calling convention for asm? I've 
 found
 extern(C) for cdecl calling convention, and i have seen mention of the
 'naked' keyword but cant work out where it goes... im not even sure if it
 does cause register calling convention or just causes the compiler to 
 omit
 entry and exit code.

 I assume it must be possible to write asm functions that take arguments 
 in
 the eax,ecx,edx registers?

 thanks,

 cw

You put 'naked' at the top of a function body, and it causes the compiler to omit the function prelude and prologue. So, for example: void breakpoint() { naked; asm { int 3; } } Compiles literally as INT 0x3 As for arguments in registers, you can't do that. If you want to have a function that you pass arguments to via registers, then you need to "call" it using asm.

Eeek! I think i'll just suck up the overhead and use extern(C) then. ;-) cw
Mar 12 2007
prev sibling parent reply Mikola Lysenko <mclysenk mtu.edu> writes:
Chris Warwick wrote:
 What do i need to do to get register calling convention for asm? I've found 
 extern(C) for cdecl calling convention, and i have seen mention of the 
 'naked' keyword but cant work out where it goes... im not even sure if it 
 does cause register calling convention or just causes the compiler to omit 
 entry and exit code.
 
 I assume it must be possible to write asm functions that take arguments in 
 the eax,ecx,edx registers?
 
 thanks,
 
 cw 
 
 

Yes, and no. The D calling convention differs from compiler to compiler. GDC uses an extension of extern(C), while DMD follows a convention similar to Win32's stdcall. As a result, this makes it a bad idea to use 'naked' within a D function. Hope this helps. -Mik
Mar 12 2007
parent Daniel Keep <daniel.keep.lists gmail.com> writes:
Mikola Lysenko wrote:
 Chris Warwick wrote:
 What do i need to do to get register calling convention for asm? I've
 found extern(C) for cdecl calling convention, and i have seen mention
 of the 'naked' keyword but cant work out where it goes... im not even
 sure if it does cause register calling convention or just causes the
 compiler to omit entry and exit code.

 I assume it must be possible to write asm functions that take
 arguments in the eax,ecx,edx registers?

 thanks,

 cw

Yes, and no. The D calling convention differs from compiler to compiler. GDC uses an extension of extern(C), while DMD follows a convention similar to Win32's stdcall. As a result, this makes it a bad idea to use 'naked' within a D function. Hope this helps. -Mik

I don't think it's supposed to differ, at least on the same platform. I think the main problem was that D's calling convention wasn't actually written down anywhere until fairly recently. That said, I have no idea if there are plans to make GDC use the same calling convention as DMD... -- Daniel -- Unlike Knuth, I have neither proven or tried the above; it may not even make sense. v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
Mar 12 2007