assembly code in c++ program

This is a discussion on assembly code in c++ program within the C++ Programming forums, part of the General Programming Boards category; Code: #include<iostream.h> #include<stdio.h> main() { __asm { push 10 push 20 } abc(); __asm { add esp,8 } } int ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    19

    assembly code in c++ program

    Code:
    #include<iostream.h>
    #include<stdio.h>
    main()
    {
    __asm
    {
    push 10
    push 20
    }
    abc();
    __asm
    {
    add esp,8
    }
    }
    int abc(int i , int j)
    {
    printf("%d %d\n", i , j);
    }


    when i am executing this code ...the error i am getting is
    cannot open program database 'c:\program files\microsoft visual studio\vc98\bin\debug\vc60.pdb'

    Do i need to make any special settings to execute this code.....
    Last edited by Brij; 09-24-2006 at 04:53 AM.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    This:
    Code:
    #include<iostream.h>
    int main()
    {
      __asm
      {
        push 10
        push 20
      }
      abc();
      
      __asm
      {
        add esp,8
      }
    
      return 0;
    }
    
    int abc(int i , int j)
    {
      printf("%d %d\n", i , j);
    }
    Is this:
    Code:
    int main()
    {
      abc(10,20);
    
      return 0;
    }
    
    int abc(int i , int j)
    {
      printf("%d %d\n", i , j);
    }
    The 10 and 20 parameters may be passed in different order depending on the call type specified for the function.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    19
    hi bubba ....

    sorry can not make out anything from ur reply .............
    are u questioning me about the order of parameters?

    as far as my code is concerned .......
    this code is equalant to
    __asm
    {
    push 10
    push 20
    }
    abc();

    __asm
    {
    add esp,8
    }


    int abc(20,10);

  4. #4
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    I see the last answer is by maxorator and thought he is going to show his assembly skills.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  5. #5
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    To OP: Make sure you are running program in debug mode.
    What compiler are you using?
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  6. #6
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by siavoshkc
    I see the last answer is by maxorator and thought he is going to show his assembly skills.
    I am not here to solve problems with in-line assembly used in C++.
    Also I am not a Visual C++ expert.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  7. #7
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Ask yourself: Is assembly needed? If it isn't, don't use it.

    Doesn't the call to the function have to be inside the asm { } blocks? Otherwise, wouldn't it try to call abc() normally, causing a compiler error since no such function exists? Something like:
    Code:
    asm {
    push 10
    push 20
    call abc
    add esp, 8
    }
    Be correct? (Perhaps call _abc if the functions have underscores...?) This works for me, but I use MinGW (which uses AT&T syntax instead of Intel (which I personally hate...)). I don't think this will work in MSVC.
    Code:
    #include <stdio.h>
    
    __cdecl void abc(int a, int b)
    {
    	printf("a = %d, b = %d.\n", a, b);
    }
    
    int main()
    {
    	asm("				\n\
    		pushl $10		\n\
    		pushl $30		\n\
    		call _abc		\n\
    		addl $8, %%esp	\n\
    		"
    		:
    		:
    		: "memory");
    	return 0;
    }
    No expert here... the only thing I've ever (really) done in assembly was for my TI-83+. And a tiny bit of x86.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  8. #8
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    I'm telling you all the asm code you have there is the same as doing this in C:

    Code:
    abc(10,20)
    The compiler will take this line and push the value 20 and 10 onto the stack and then call abc - but more appropriately will probably call an address where abc is instead of actually calling the function name. Compiler assembly code when disassembled is quite confusing.

    And no that AT&T syntax will not work on MSVS...thank goodness. AT&T syntax is hideous.

    You can call functions from inline asm in MSVS but you cannot call class member functions. This is because the functions don't resolve to an address using the same algo or method as normal C functions. A class is a totally different beastie.

    For more information on inline assembly in MSVS consult the MSVS help file. It has an entire section concerning assembly, mixing C/C++ with assembly, allowed data types, addressing modes, class member addressing, etc, etc.

  9. #9
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    You use
    Code:
    #include <iostream.h>
    This is dated and most modern compilers will flag an error or a warning. Change it to
    Code:
    #include <iostream>
    You must be using an old compiler /IDE. Which one is it? There are many good and free updated
    ones avalible. One good one is DevC++ and code::blocks. Also, Microsoft have the express edition of MSVC++2005 on download from their site.

  10. #10
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    Wait for the OP's new post.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I need the code of few programs in c++.plzzzzz help...plzzz
    By NAVINKR20 in forum C++ Programming
    Replies: 1
    Last Post: 05-08-2009, 09:13 AM
  2. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 02:30 PM
  3. Can someone help me understand this example program
    By Guti14 in forum C Programming
    Replies: 6
    Last Post: 09-06-2004, 12:19 PM
  4. Please test my program: Code Black
    By PhoenixC++ in forum Windows Programming
    Replies: 15
    Last Post: 04-29-2004, 07:18 PM
  5. Program Code
    By anewhope in forum C Programming
    Replies: 0
    Last Post: 04-22-2002, 09:06 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21