Solved

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Buffer Bomb Level 0 23 7,897
new build power loop at boot no POST or beeps - new cpu, motherboard and PS 7 2,277
DOS Dongle bypassing 10 1,618
wrong referenced assembly version  (using VS 2008) 3 224
Enabling the Skype for Business Meeting Scheduler in Hybrid OWA
Direct mail marketing is the act of mailing materials straight to prospective customers. This wide form of marketing is one of the oldest methods of communicating with a geographic based demographic. So is it useful in 2017 and beyond?
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

679 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