CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Other Programming > Assembly
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Assembly Questions and Answers for Assembly here!

    Reply
     
    Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
      #1    
    Old September 2nd, 2004, 02:05 AM
    doitlong doitlong is offline
    Junior Member
     
    Join Date: Aug 2004
    Posts: 6
    doitlong is on a distinguished road (10+)
    Question C++ inline ASM

    Code:
    #include <stdio.h>
    
    class CHello{
    public:
    	void fun()
    	{
    		printf("Hello World");
    	} 
    };
    
    void main()
    {
    	CHello hello;
    	_asm{
    		LEA EAX,hello
    		CALL [EAX]hello.fun
    	};
    }
    /-------------------------------------------------------------------

    error C2411: 'fun' : illegal struct/union member in 'first operand'

    -------------------------------------------------------------------/

    Tools : VC++6.0
    Reply With Quote
      #2    
    Old July 2nd, 2005, 11:46 AM
    Alkhimey Alkhimey is offline
    Junior Member
     
    Join Date: Apr 2005
    Posts: 2
    Alkhimey is an unknown quantity at this point (<10)
    Re: C++ inline ASM

    CALL [EAX]hello.fun()
    Reply With Quote
      #3    
    Old July 2nd, 2005, 03:11 PM
    NoHero's Avatar
    NoHero NoHero is offline
    Moderator
     
    Join Date: Mar 2004
    Location: (Upper-) Austria
    Posts: 2,899
    NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)
    Re: C++ inline ASM

    The thing you are trying to do has following issues:
    • You cannot use C++ OOP within a low level language because you do not know how it is implemented and internaly represented by the compiler.
    • When you try to do it, and get an hack for a compiler this hack is compiler depended, because any compiler does it another way.
    • A member function is (most time) nothing else than a normal function which get's internally a pointer to a structure containing all data members of the class. The problem now: You either don't know how to call the function, because you do not know it's name and you cannot "extract" the internal structure from the class.
    • Everything would be mixed up when using virtual members, because they are stored as function pointer table inside the hidden structure.
    • And digging as deep as you are trying to do, is not the way it supposed to be. You should get your nose out of this, otherwise it will cause a lot of strange bugs you aren't able to identify or even fix them.

    To cut the long story: What you are trying todo is not fine coding style and (nearly) impossible.
    __________________
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!
    Reply With Quote
      #4    
    Old July 3rd, 2005, 12:03 PM
    BytePtr's Avatar
    BytePtr BytePtr is offline
    Member
     
    Join Date: May 2005
    Location: Estonia
    Posts: 190
    BytePtr has a spectacular aura about (150+)BytePtr has a spectacular aura about (150+)
    Re: C++ inline ASM

    Code:
    #include <stdio.h>
    
    char format[] = "%s %s\n";
    char hello[] = "Hello";
    char world[] = "world";
    void main( void )
    {
       __asm
       {
          mov  eax, offset world
          push eax
          mov  eax, offset hello
          push eax
          mov  eax, offset format
          push eax
          call printf
          pop  ebx
          pop  ebx
          pop  ebx
       }
    }
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Other Programming > Assembly


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 03:52 PM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009