News:

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

Main Menu

TVector problem?

Started by HSE, January 28, 2024, 07:01:11 AM

Previous topic - Next topic

HSE

Hi Biterider!

Look like there is a problem in InsertAt method:

    OCall xbx::DWordVector.Insert, 15
    OCall xbx::DWordVector.Insert, 14
    -----------------------------------
    OCall xbx::DWordVector.InsertAt, 0, 15
    OCall xbx::DWordVector.InsertAt, 0, 14

Test DWordVector
──────────────────────────────────────────────────────────────────────
esi = 0
DWORD ptr [xax] = 15
esi = 1
DWORD ptr [xax] = 14
──────────────────────────────────────────────────────────────────────
esi = 0
DWORD ptr [xax] = 14
esi = 1
DWORD ptr [xax] = -144682624

Thanks in advance, HSE.
Equations in Assembly: SmplMath

Biterider

#1
Hi Hector
Thanks for the testbed code.
You are right  :thumbsup:
I put the value assignment line in the wrong place.
I have attached the corrected version of TVector.inc.

Looking into
.for (esi = 0 : esi != [xbx].$Obj(DWordVector).dCount : esi++)
  DbgDec esi
  OCall xbx::DWordVector.ItemAt, esi
  DbgDec DWORD ptr [xax]
.endfor
it works perfectly fine!

It could also be written like this
.VecForEach [xbx].$Obj(DWordVector), esi
  DbgDec esi
  DbgDec DWORD ptr [xax]
.VecNext
which is a bit more efficient, since it does not call .ItemAt

An alternative using implicit indexing is
.VecForEach [xbx].$Obj(DWordVector)
  DbgDec DWORD ptr [xax]
.VecNext

Looking at the disassembly, I discovered an instruction that can be omitted. This little optimisation is implemented in the attached file.

Regards, Biterider

HSE

Hi Biterider!

 Perfect now :thumbsup:

Thanks, HSE
Equations in Assembly: SmplMath