?
Solved

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

Posted on 2003-12-02
3
Medium Priority
?
504 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
[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
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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

WooCommerce is becoming the most powerful e-commerce plugin for Wordpress. And why not. The platform comprises of numerous core plugins that may come in handy, powerful options to make your website development task much easier.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

650 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