using C++ code with assembly 
Author Message
 using C++ code with assembly

Hi,
I am a newbie to assembly language. I want to link C++ code with assembly
code. For example I have a function

    void foo(void)

written in C++.
Now i want to use this function in my assembly language programs.

I declared it like this

    fooA proto stdcall
    foo textequ<fooA>

and used it like

    invoke foo

I am linking properly both the C++ and Assembly *.obj files, but I am
getting linker errors.

Can you tell me how I can do this.

I also want to know how I can call a assembly routine from C++.

Thanks,
Regards,
Sadish



Wed, 26 Sep 2001 03:00:00 GMT  
 using C++ code with assembly

Quote:

> Hi,
> I am a newbie to assembly language. I want to link C++ code with assembly
> code. For example I have a function

>     void foo(void)

> written in C++.

Since C++ is a 'strongly typed' language, the functions written in it do
not generally look out like you think. This is because C++ compilers
'mangle' function names to contain parameter and return type
information. How they do that, depends on the compiler used. For
example, a function

        void foo(void)

compiled with MSVC/C++ v5 gives produces the name


instead of just foo or _foo for the function. You should turn on the
'generate list file' or 'generate map file' for the compiler and look
through that to see what name your compiler gives to the function.

Another alternative is to write the function in the C++ source as:

extern "C" {
void    foo(void)
{ ... }

Quote:
}       // end of extern "C"

This fill produce the normal C style function name.

Quote:
> I also want to know how I can call a assembly routine from C++.

You can write an assembler routine (remember to make it public) in the
ASM source, for example (again, this depends on your assembler syntax):

        ...
        public  _name   ; leading underscore in the name!
        ...
_name   proc
        ...
_name   endp

And then introduce the function in the C++ source as (of course,
parameters and return values should be properly defined):

extern "C" void name(void);   // "C" tells the compiler to use C style
....
        name(); // function call as usual

HTH,
        AriL
--
Humans may send email (if absolutely necessary) to the
obvious non-spam address.



Sun, 30 Sep 2001 03:00:00 GMT  
 using C++ code with assembly
Hi,
Thanks a lot. That worked like a charm.

Thanks,
Regards,
Sadish



Mon, 01 Oct 2001 03:00:00 GMT  
 using C++ code with assembly
If your using a DOS/Windows C++ compiler (and its a C++ program, not C):

extern "C" { void foo(void); }

Also, C/C++ puts an underscore infront of the function name:

Example:

public _foo
_foo:
        push    ebp
        mov     ebp,esp
        ...
        mov     esp,ebp
        pop     ebp
        retn

Quote:

> Hi,
> I am a newbie to assembly language. I want to link C++ code with assembly
> code. For example I have a function

>     void foo(void)

> written in C++.
> Now i want to use this function in my assembly language programs.

> I declared it like this

>     fooA proto stdcall
>     foo textequ<fooA>

> and used it like

>     invoke foo

> I am linking properly both the C++ and Assembly *.obj files, but I am
> getting linker errors.

> Can you tell me how I can do this.

> I also want to know how I can call a assembly routine from C++.

> Thanks,
> Regards,
> Sadish

--

Home Page: "http://members.xoom.com/fredlie/"


Mon, 01 Oct 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. C++ idea in assembly or how C++ code becomes an exe

2. C++ idea in assembly or how C++ code becomes an exe

3. Assembly coding in C++ compiler, help need

4. call assembly code from C++

5. how to inline assembly code to visual c++

6. Visual C++ and assembly code

7. Using assembly inside C++

8. Problem Using PCSPIM for loading MIPS Assembly Code

9. using assembly code in turbo pascal 5

10. using assembly code in turbo pascal 5

11. problem porting assembly codes from ms inline assembly to linux (gnu - AT&T syntax)

12. Using Clarion 5 to Compile C or C++ source code

 

 
Powered by phpBB® Forum Software