Author Topic: LinkedList example?  (Read 3581 times)

HSE

  • Member
  • ****
  • Posts: 552
  • <AMD>< 7-32>
LinkedList example?
« on: June 03, 2015, 12:22:15 AM »
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   
 

jj2007

  • Member
  • *****
  • Posts: 7752
  • Assembler is fun ;-)
    • MasmBasic
Re: LinkedList example?
« Reply #1 on: June 03, 2015, 12:46:10 AM »
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

  • Moderator
  • Member
  • *****
  • Posts: 126
  • ObjAsm32
    • ObjAsm32
Re: LinkedList example?
« Reply #2 on: June 03, 2015, 06:24:03 AM »
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

  • Member
  • ****
  • Posts: 552
  • <AMD>< 7-32>
Re: LinkedList example?
« Reply #3 on: June 04, 2015, 01:07:22 AM »
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

Gunther

  • Member
  • *****
  • Posts: 3517
  • Forgive your enemies, but never forget their names
Re: LinkedList example?
« Reply #4 on: June 04, 2015, 01:36:56 AM »
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
Get your facts first, and then you can distort them.

HSE

  • Member
  • ****
  • Posts: 552
  • <AMD>< 7-32>
Re: LinkedList example?
« Reply #5 on: June 05, 2015, 12:29:35 AM »
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

 

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 126
  • ObjAsm32
    • ObjAsm32
Re: LinkedList example?
« Reply #6 on: June 06, 2015, 05:02:23 PM »
Hi HSE
If you are not comming foreward, PM me.

Biterider

HSE

  • Member
  • ****
  • Posts: 552
  • <AMD>< 7-32>
Re: LinkedList example?
« Reply #7 on: June 07, 2015, 01:53:20 AM »
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


HSE

  • Member
  • ****
  • Posts: 552
  • <AMD>< 7-32>
Re: LinkedList example?
« Reply #8 on: June 08, 2015, 02:52:23 AM »
For show the code I'm using a fictional object:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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
« Last Edit: June 08, 2015, 11:26:34 AM by HSE »

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 126
  • ObjAsm32
    • ObjAsm32
Re: LinkedList example?
« Reply #9 on: June 09, 2015, 12:57:54 AM »
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

  • Member
  • *****
  • Posts: 8751
  • Still using Abacus 2.0
    • DednDave
Re: LinkedList example?
« Reply #10 on: June 09, 2015, 10:27:12 AM »
puntito = small point, point, dot, maybe pixel ?, maybe pointer ?

caballero

  • Member
  • ****
  • Posts: 782
    • Abre Ojos Ensamblador
Re: LinkedList example?
« Reply #11 on: June 09, 2015, 06:04:55 PM »
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.

Code: [Select]
       |----|---|      |----|---|
0 <--- |    |   | <--- |    |   | <--- ...
       |--------|      |--------|

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

Un saludo,
alfonso
En un lugar de la Mancha de cuyo nombre no quiero acordarme

HSE

  • Member
  • ****
  • Posts: 552
  • <AMD>< 7-32>
Re: LinkedList example?
« Reply #12 on: June 10, 2015, 12:04:06 AM »
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. 

Code: [Select]

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

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 126
  • ObjAsm32
    • ObjAsm32
Re: LinkedList example?
« Reply #13 on: June 11, 2015, 03:12:32 AM »
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

  • Member
  • ****
  • Posts: 552
  • <AMD>< 7-32>
Re: LinkedList example?
« Reply #14 on: June 11, 2015, 03:54:15 AM »
Thank you Biterider.

With an example is a lot more easy!

HSE