×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Using Linked Lists in ASM...

Using Linked Lists in ASM...

Using Linked Lists in ASM...

(OP)
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:

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

RE: Using Linked Lists in ASM...

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."

RE: Using Linked Lists in ASM...

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."

RE: Using Linked Lists in ASM...

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close