Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

linking objects

Posted on 2004-03-27
6
Medium Priority
?
240 Views
Last Modified: 2010-04-01
how can i link assembly objects with object that compiled on turbo c++
0
Comment
Question by:akayed
3 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 10697374
Add the objects to your link command in your project settings.
0
 
LVL 17

Accepted Solution

by:
rstaveley earned 180 total points
ID: 10697447
Let's assume you have a void function which takes no parameters, which prints "Hello, world" in C tradition. The function is, however, written in assmembler. Let's call the function Hello().

Here's a possible TASM/MASM source.

hello.asm:
--------8<--------
.MODEL small,C
.DATA
    message DB "Hello, world$"
.CODE
PUBLIC Hello
Hello PROC NEAR
    MOV AH,9  
    MOV DX,OFFSET message
    INT 21h
    RET
Hello ENDP
END
--------8<--------

The memory model matches the memory model used in the C/C++ compilation. The .MODEL is supplied the C specifier to prefix public symbols with a leading underscore just like C does. That way the Hello PROC is seen by the linker as _Hello. .CODE and .DATA names segments in the same way that they are named by C programs.

In your C++ module you should prototype the Hello function with extern "C" to prevent C++ name-mangling.

main.cpp:
--------8<--------
extern "C" void Hello(void);

int main()
{
        Hello();
        return 0;
}
--------8<--------

You can use tcc to compile main.cpp and ink it with the start-up code, libraries and hello.obj thus:

        tcc main.cpp hello.obj

Alternatively, you can add hello.obj to the link in the IDE.
0
 
LVL 3

Expert Comment

by:CoolBreeze
ID: 10956263
I would recommend accept rstaveley's answer.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question