Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Linked Lists in ASM...

Status
Not open for further replies.

karmaPolice

Programmer
Oct 26, 2002
1
MX
I have a problem, I have to use C++ and ASM to make a program, here is the description:
I have to make a program in C++ that creates a Linked List of doubles and then in ASM using the list just add every number on it. That's all.

I have the C++ part, I just don't know how to advance through the linked list

The ASM prototype should be:
addDoubles(List l, int listSize);

and here is the C++ part, just the important:
Code:
class node {
	void* info; //info could be int, double, char, etc.
	node* next;

public:
	node (void* v) {
		info =v;
		next=0;
	}
	void poner_next (node*n){
		next = n;
	}
	node* read_next(){
		return next;
	}
	void* read_info(){
		return info;
	}
};

class list{
	node* header;
	int node_num;
	
public:
	list(){
		node_num = 0;
		header = 0;
	}
	void remove(int);
	void insert (void*, int);
	void put (void* v){
		insertar (v, node_num+1);
	}
	void* find(int);
	void print();
};

Thanks
 
Interfacing between C++ and ASM can be ridiculously difficult. The difficulty lies in the fact that in C++, the compiler puts more in each class than you put in. What is more, (at least in the past) different C++ compilers did not necessarily compile in the same manner. If you are using MSVC++, you may wish to find documentation on COM for ASM programmers; since COM is mostly based on MS's C++'s class structure, you may *glean* some information there.

It seems safe to indicate that any class is equivalent to a struct:
struct node
{
void (*vf_table); /*virtual functions table*/
void *info;
node *next;
};
However I am not certain of the placement of the vf_table, or if the elements have a special arrangement with regards to privacy.

Ja! Have fun! "Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
You might also try to *SEARCH* on win32asmboard.cjb.net . Some of the people there have had to face problems of interfacing C++ to ASM, and they may have posted some things you can use. The point though is to use the *SEARCH* function on win32asmboard.cjb.net since if you ask, you stand a 50-50 chance of getting answered with a 'use the search function' post. "Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
I assume you're writing this in assembler because it's an assignment or something - otherwise you'd just write it in C.
The aim of the assignment is presumeably to learn what a C linked list really looks like, and how to address it - and in any case that is the real difficulty: adding numbers on a linked list in assembler is just a load of lea's or les's and adds.

One very obvious approach is to write the routine in C (a very simple task), and then disassemble it. What I usually do is just save the routine itself as a file, not all the rest of the exe, and then disassemble that. Of course it would be utterly cheating and utterly pointless to hand in the disassembly and pretend it was your own assembler routine, but looking at what your C compiler generates is the perfect way to find out how parameters like the base address of the list are passed, and what structure the compiler has made for the list. What's more, you can use this approach whatever your compiler, and even in different languages with different ways to pass things...
Not only would it be cheating and pointless to use the disassembled C as assembler: it would be very obvious to anyone who looked (compiler-generated code is very easy to recognise), and all the advantages of going for assembler would be lost. For instance, for a little routine like this you may not have to handle the stack frame fully.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top