The MASM Forum

Projects => ObjAsm => Topic started by: HSE on January 28, 2024, 07:01:11 AM

Title: TVector problem?
Post by: HSE on January 28, 2024, 07:01:11 AM
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.
Title: Re: TVector problem?
Post by: Biterider on January 28, 2024, 08:31:33 PM
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
Title: Re: TVector problem?
Post by: HSE on January 29, 2024, 01:23:52 AM
Hi Biterider!

 Perfect now :thumbsup:

Thanks, HSE