Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

linking objects

Posted on 2004-03-27
6
Medium Priority
?
239 Views
Last Modified: 2010-04-01
how can i link assembly objects with object that compiled on turbo c++
0
Comment
Question by:akayed
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

715 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