Solved

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

Posted on 2003-12-02
3
473 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now