News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

LinkedList example?

Started by HSE, June 03, 2015, 12:22:15 AM

Previous topic - Next topic

HSE

Hi!
I'm triying to learn masm32 programing for 15 years now!
In the midtime I also learn and use Java for some scientific modelling applications.
These days one of that little projects is becoming ObjAsm. Some ObjAsm objects are still less developed that in Java. The documentation is non existing, and we need to understand the use from the code. Very funny but slow. Also there is some very good projects examples but they don't show all the posibilities.

If there is some LinkedList examples I will save a lot of time (I think).

Thanks. HSE   

Equations in Assembly: SmplMath

jj2007

Hi HSE,

Welcome to the Forum :icon14:

What do you want to achieve? Why a linked list, why ObjAsm instead of plain Masm32? You probably have good reasons, but it's better to reveal them, so you'll get better advice...

Why you should never, ever, EVER use linked-list in your code again

Biterider

Hi HSE
I'm sorry, but i think you will not find an isolated example of the use of a linked list in the released software package.
I implemented linked lists in 2 ways. As an object that i rarely use (LinkedList) or as a set of macros. The macros implement single and dual, linear and sentinel linked lists.
Linked lists are fast and with little effort they can be used in an MT environment.
Look into the sources (LDLL.inc, SDLL, etc.) and search for the use of these files in the sources to find the way to use them.

In regard to the documentation, I wrote a help file (\ObjAsm32\Help\ObjAsm32.chm) containing all the basics starting from notation and conventions to the complete use of the object model. It also includes a description of a few demo applications. On the other hand, if you have installed the package, you have an object explorer (OA32_ObjectBrowser) that gives you the most relevant information about your objects.

Regards, Biterider

HSE

Hi! Thanks for the welcome.

jj2007:

You are completily right. For the little application I am translating, OOP is no needed at all, the mathematical model is plain. Is mostly a training for more complex mathematical models in wich objects are a straigthful representation of independent entities like cows in a herd or pastures in a farm (herd and farm are the "linked list"). 

Very interesting Kjellkod's article. I mess with a little piece of code in ObjAsm32 linkedlist because I am thinking in the "naive" linkedlist while aparently it's the "smart" one. At this moment the problem it's in the range of little diferences. Later i will see what to do (and search what a C++ vector is).

Biterider:   

If in this forum people don't know an example, then the example dont't exist!

The help is very useful for running the examples and debugging. But nothing say about the objects. I didn't even suspect that a complete set of objects exist. What a surprise when search in the code directory!

Perhaps part of the problem was that I lost the ObjectBrowser trying to compile it (at least I don't have oldnames.inc for that). I have reinstalled the executable from the package, and now I can see the objects. Still poorly documentation of the objects, but much more better. I will keep trying.

Thanks. HSE
Equations in Assembly: SmplMath

Gunther

Hi HSE,

first things first: Welcome to the forum.

Jochen's question remains: Why realize a linked list with ObjAsm? Have you checked Donald Knuth's The Art of Computer Programming, Volume 1, Fundamental Algorithms? He uses a kind of assembly language to describe the different methods and algorithms which is easy to take over into Intel syntax. You'll find that topic at the pages 234-237, 264-266 and 269.

Gunther
You have to know the facts before you can distort them.

HSE

Hi Gunther!

One day after reading a few pages I understood what all of you are trying to say (or you are saying but I am not understanding).
When I was using TPascal, a lot of years ago, I think that was named "direct chaining" and what the LinkedList objet do "indirect chaining". Of course the former is the way that I wasn't seeing.:eusa_clap:

But I say to my collegues that "with assembler we can do all the thing what we can do with whatever programming language" (but in Spanish). Because a that I will insist for a while. I thing that the LinkedList is going to work, even when I am in a nightmare of pointers that, finally, don't are pointing to anything!

Thanks again  :eusa_clap:. HSE

Equations in Assembly: SmplMath

Biterider

Hi HSE
If you are not comming foreward, PM me.

Biterider

HSE

Thank Biterirder!

The LinkedList is working very well now. A younger my self come to help me. I found my own old little code that implement the original Beeker-NaN OOP framework . That refresh some of the basics I almost forget.
I'll post some code lines later (for improvement or ideas).

Regards, HSE

Equations in Assembly: SmplMath

HSE

#8
For show the code I'm using a fictional object:

Object Test, , Primer
        ...
Embed puntosP, LinkedList
...
VirtualMethod LoadPuntito,qword,qword
VirtualMethod LookPuntito
ObjectEnd


For link a new object to the list there is no problem:

Method Test.LoadPuntito, uses esi, x:qword, y: qword
    SetObject esi

New Puntito
OCall eax::Puntito.Init, x, y    ;Initialize Puntito instance values
OCall [esi].puntosP::LinkedList.Append, eax

MethodEnd


Retrieve the object from the list work very well:

SetObject eax, LinkedList, [esi].puntosP
mov ecx , [eax].pCurrentNode
SetObject ebx, Puntito, [ecx+8]

But perhaps there is a way more direct (without using a register, in this case ecx), or at least the same thing can be written in a more meaninfull way (thinking in indirect access from structures more complex than LINKED_NODE, or that could be modified).

edited later:
  [ecx].LINKED_NODE.pObject work fine, obviously I was making something wrong.

That code seems usefull for travelling along the entire list:

Method Test.LookPuntito, uses esi
        SetObject esi
   
        OCal [esi].puntosP::LinkedList.GetFirst
        SetObject eax, LinkedList, [esi].puntosP
push eax
mov ecx , [eax].pCurrentNode
.if ecx == NULL
.else
.repeat
SetObject ebx, Puntito, [ecx+8]
DbgFloat [ebx].x   
DbgFloat [ebx].y   
 
OCall [esi].puntosP::LinkedList.GetNext
pop eax
push eax
mov ecx , [eax].pCurrentNode
.until ecx == NULL
.endif
pop eax
MethodEnd


Thanks, HSE
Equations in Assembly: SmplMath

Biterider

Hi HSE
I miss the definition of Puntito. Can you post your code so I can look into it to give you a hit how to reference Puntito?

Biterider

dedndave

puntito = small point, point, dot, maybe pixel ?, maybe pointer ?

avcaballero

Buenos días. Las listas, colas, árboles son una herramienta poderosa de programación. Que alguien me diga cómo hacer un foro sin listas o colas... Los árboles son muy importantes también para dotar de inteligencia artificial a los juegos, por ejemplo.


       |----|---|      |----|---|
0 <--- |    |   | <--- |    |   | <--- ...
       |--------|      |--------|


Si tengo tiempo podría subir un pequeño ejemplo de listas simplemente enlazadas, si estás interesado.

Un saludo,
alfonso

HSE

Hi!

Exactly, Puntito is a point. It store the coordinates for make a graphic. Of course in this case is totally inefficient to use LinkedList (LINKED_NODE size is 12 bytes) for linking 16 bytes objects.

Remember that I am trying to implement correctly a LinkedList. I found the LDLL and LSLL macros and later I will try to use them for a direct linking, like JJ and Gunther strongly suggest. 



Object Puntito,, Primer
DefineVariable x, qword, 0.0
DefineVariable y, qword, 0.0
RedefineMethod Init,QWORD, QWORD
ObjectEnd

Method Puntito.Init,uses esi, x1:QWORD, y1:QWORD
    SetObject esi
    finit
    fld x1
    fstp [esi].x
    fld y1
    fstp [esi].y
MethodEnd



If you have a good code, it's welcome. Thanks. HSE
Equations in Assembly: SmplMath

Biterider

Hi HSE
As a hint on how to use a linked list, tale a look into the Memrecycler project.
The Datapool object (Datapool.inc) uses a structure called DPL_CONTROLDATA where a SDLL is used to link the memory chunks.
Going through the code, you will see several calls like "SDLL_Init edi" which are invokations to the SDLL macros.

Biterider


HSE

Thank you Biterider.

With an example is a lot more easy!

HSE
Equations in Assembly: SmplMath