[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 510
  • Last Modified:

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

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
stubuf612
Asked:
stubuf612
1 Solution
 
grg99Commented:
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
 
stubuf612Author Commented:
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
 
mtmikeCommented:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now