digitalmars.D.learn - Register calling convention for asm functions...
- Chris Warwick (9/9) Mar 11 2007 What do i need to do to get register calling convention for asm? I've fo...
- Daniel Keep (12/24) Mar 11 2007 You put 'naked' at the top of a function body, and it causes the compile...
- Chris Warwick (4/32) Mar 12 2007 Eeek! I think i'll just suck up the overhead and use extern(C) then. ;-)
- Mikola Lysenko (7/21) Mar 12 2007 Yes, and no. The D calling convention differs from compiler to
- Daniel Keep (12/35) Mar 12 2007 I don't think it's supposed to differ, at least on the same platform. I
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
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, cwYou 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
"Daniel Keep" <daniel.keep.lists+dm gmail.com> wrote in message news:et2kt5$2g7c$1 digitalmars.com...Chris Warwick Wrote:Eeek! I think i'll just suck up the overhead and use extern(C) then. ;-) cwWhat 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, cwYou 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.
Mar 12 2007
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, cwYes, 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
Mikola Lysenko wrote:Chris Warwick wrote: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/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, cwYes, 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