Thread: Virtual function and multiple inheritance

  1. #46
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by George2 View Post
    Thanks Elysia and Mats,


    Do you know whether Microsoft provides online free manual for the assembly language guide with Visual Studio (i.e. how Visual Studio compiler's assembly language looks like, e.g. which register is used to hold this pointer or something, other than a general assembly language guide)?


    regards,
    George
    The calling conventions for each of the supported language and processor type is documented in the respective language on MSDN, e.g: http://msdn2.microsoft.com/en-us/lib...58(VS.71).aspx

    For C/C++ 32-bit x86 it is roughly (I wrote that before looking at MSDN):
    EAX - return value, otherwise scratch register.
    EDX - upper 32-bits of 64-bit return value, otherwise scratch register.
    ECX - this when using "thiscall", otherwise scratch.
    EBX - preserved by callee.
    EDI - preserved by callee.
    ESI - preserved by callee.
    EBP - preserved by callee.
    ESP - stack pointer - varying between call form whether caller or callee cleans up arguments.

    I think EAX, EDX and ECX are used for the three first args in "fastcall" calling convention - but I may be wrong on the exact registers.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #47
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by matsp View Post
    I think EAX, EDX and ECX are used for the three first args in "fastcall" calling convention - but I may be wrong on the exact registers.
    That's gcc I believe. W32 passes them in ECX, EDX order.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #48
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Mario F. View Post
    That's gcc I believe. W32 passes them in ECX, EDX order.
    Quite right - clicking on the "fastcall" link in the page I posted a link to will show that.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #49
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks CornedBee,


    1.

    ABI is short for? :-)

    2.

    My assembly book is pretty old -- IBM 80x86 book. Could you recommend some assembly language book which conforms (more) to modern compiler and runtime, especially Win32/Win64? I would like to buy a new one after having discussion in this thread with you.

    Quote Originally Posted by CornedBee View Post
    The probably have an ABI guide somewhere, but they'd be pretty stupid to document anything beyond that.

    regards,
    George

  5. #50
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    ABI is short for?
    Application Binary Interface
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #51
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    In other words, the low-level conventions program code must follow in order to interoperate with other code.

    No idea about assembly books. I never had one. All information I need I take directly from Intel's tech reference.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #52
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by CornedBee View Post
    In other words, the low-level conventions program code must follow in order to interoperate with other code.

    No idea about assembly books. I never had one. All information I need I take directly from Intel's tech reference.
    And if you don't want Intel manuals, AMD has a complete set of 5 books (in PDF unless you have GOOD contacts within AMD to get you the hardcopy version). Here for the soft copies.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #53
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    And here's the Intel variant of pretty much the same thing.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #54
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks CornedBee,


    Well. I think I have not made myself understood. I think there should be some assembly language manual provided by Microsoft other than by AMD/Intel, because I think to decide ECX should contain this pointer should be decided by Microsoft compiler, right?

    What I want is general assembly language + specific things for Windows platform, like ECX for this.

    Quote Originally Posted by CornedBee View Post
    And here's the Intel variant of pretty much the same thing.
    Thanks laserlight,


    Quote Originally Posted by laserlight View Post
    Application Binary Interface
    Is there a book for that? On MSDN or?


    regards,
    George

  10. #55
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    I think there should be some assembly language manual provided by Microsoft
    You're looking for the ABI description. This has very little to do with assembly language, so an assembly language manual by Microsoft doesn't make sense.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  11. #56
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I'm not sure such a thing exists. Microsoft certainly wouldn't go round and write a book that contains all the info from AMD & Intel. On the other hand, AMD & Intel won't reproduce the ABI from Windows or Linux. I don't know if there is a proper documented ABI published by MS, but Linux certainly have a document that describes the ABI.

    Searching Amazon.co.uk for "assembler Windows", it gives only two titles, and both are 15+ years old. "Intel Assembler" gives 43 titles, some of which are pretty recent, "AMD Assembler" gives one title in German. I doubt any of these books are particularly targetting Windows programming - once you know how to program assembler in general, using Windows calls is just a case of applying the ABI to function calls, after all.


    In lack of such a document, the calling convention is reasonably well described on the page I linked to.

    Edit: Note to self: Don't write so much, then CorneedBee won't get there first

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #57
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Hi Mats and CorneedBee,


    Could this one be treated as ABI manual by Microsoft?

    http://www.microsoft.com/whdc/system...re/PECOFF.mspx

    Quote Originally Posted by matsp View Post
    I'm not sure such a thing exists. Microsoft certainly wouldn't go round and write a book that contains all the info from AMD & Intel. On the other hand, AMD & Intel won't reproduce the ABI from Windows or Linux. I don't know if there is a proper documented ABI published by MS, but Linux certainly have a document that describes the ABI.

    Searching Amazon.co.uk for "assembler Windows", it gives only two titles, and both are 15+ years old. "Intel Assembler" gives 43 titles, some of which are pretty recent, "AMD Assembler" gives one title in German. I doubt any of these books are particularly targetting Windows programming - once you know how to program assembler in general, using Windows calls is just a case of applying the ABI to function calls, after all.


    In lack of such a document, the calling convention is reasonably well described on the page I linked to.

    Edit: Note to self: Don't write so much, then CorneedBee won't get there first

    --
    Mats

    regards,
    George

  13. #58
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Possibly, but I don't think so. This describes the binary file formats, not the binary interfaces.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  14. #59
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    No, that describes the format of the executable file, not calling conventions etc.

    Here's a link to one page that described calling conventions:
    http://msdn2.microsoft.com/en-us/library/aa235581.aspx

    This link is one level above the previous one, and covers a whole host of further topics that may be interesting, such as inline assembler usage etc.
    http://msdn2.microsoft.com/en-us/lib...8VS.60%29.aspx

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  15. #60
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Hi Mats,


    What do you think is the difference between the PE binary format and the binary guide for calling convetion.

    1. Executable is consisting of functions, functions' binary format should be covered in PE (I think it should also cover the assembly code or binary format about the code to invoke a function);

    2. Calling convention is about how internally (including the binary assembly code) a function is called.

    So, in this way I do not think there is something you are mentioned which is not covered as a part of PE binary format Spec.

    Maybe I have not clearly understood your points. What are your ideas?

    Quote Originally Posted by matsp View Post
    No, that describes the format of the executable file, not calling conventions etc.

    Here's a link to one page that described calling conventions:
    http://msdn2.microsoft.com/en-us/library/aa235581.aspx

    This link is one level above the previous one, and covers a whole host of further topics that may be interesting, such as inline assembler usage etc.
    http://msdn2.microsoft.com/en-us/lib...8VS.60%29.aspx

    --
    Mats

    regards,
    George

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What is a virtual function pointer?
    By ting in forum C++ Programming
    Replies: 4
    Last Post: 03-05-2008, 02:36 AM
  2. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 09:04 AM
  3. inheritance and performance
    By kuhnmi in forum C++ Programming
    Replies: 5
    Last Post: 08-04-2004, 12:46 PM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  5. Exporting Object Hierarchies from a DLL
    By andy668 in forum C++ Programming
    Replies: 0
    Last Post: 10-20-2001, 01:26 PM