Solved

Accessing functions and member variables of a C++ class in NASM

Posted on 2003-12-02
3
478 Views
Last Modified: 2007-12-19
I was curious about accessing C++ classes in NASM.  I have loaded arguments passed to a function written in nasm before, but this doesn't do me a lot of good.  The class Record has three member functions to return the three private member variables: Id, Age, and Sex.  I have a flat-file database, where one record is stored per line in the following format:

Id,Age,Sex\n
Id,Age,Sex\n
and so forth

I am trying to write a program to search through the loaded database (which right now is loaded into an array of Records) with a nasm function, searchRecord, as well as print all the records loaded, printRecord.  I am having great difficulty accessing the member variables of this class, and would appreciate any help on this case.

0
Comment
Question by:stubuf612
3 Comments
 
LVL 22

Expert Comment

by:grg99
ID: 9859067
I would start out by writing the outer loop of the search in C++, and passing the fields to your NASM routine, something like:

Index = 0;

do {
        Index++;
        AgePtr = DataBase.GetAge( Index ) ;
        Found = LookUpWithNASM( AgePtr );  
   } while( ! Found && Index < MaxIndex );
0
 

Author Comment

by:stubuf612
ID: 9896262
When I define lookupwithnasm, it tells me the function is undefined, even though I prototyped it in the c++ source code.  How do I make c aware of the lovely little assembly routine I have written?
0
 
LVL 5

Accepted Solution

by:
mtmike earned 500 total points
ID: 9897588
C++ mangles function names in order to cope with overloaded functions. You can tell the compiler that 'lookupwithnasm' is a C function by writing 'extern "C"' before its prototype:

extern "C" void lookupwithnasm();

The 'lookupwithnasm' function has to be global. Put 'GLOBAL lookupwithnasm' somewhere at the start of your nasm source file.

Alternatively, write the function skeleton in C++ and let the compiler translate it to assembly. Then take a peek at the generated assembly to see what name the compiler has come up with.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Return (ret) value over-writing on x64 8 669
Binary Bomb: Phase 4 func4 3 334
Dialog Button Color 3 115
CRM 2011 Custom Code 4 54
This tutorial shows how to create a greeting card by combining two image layers and a text layer on a PC using a free image editing app.
In this increasingly digital world, security hacks are no longer just a threat, but a reality. As we've witnessed with Target's big identity hack 2013, Heartbleed in 2015, and now Cloudbleed, companies and their leaders need to prepare for the unthi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

832 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