News:

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

Main Menu

Vararg in Colletion::ForEach

Started by HSE, October 10, 2023, 05:05:40 AM

Previous topic - Next topic

HSE

Hi Biterider!

Not so elegant but look like in 32 bits this is going to work:Method CollectionV.ForEach, uses xbx xdi xsi, pActionProc:POINTER, xArg1:VARARG
  local dires[25]:POINTER
  local store: XWORD
  ArgReg pActionProc:rdx

    dec xax
    mov store, xax
    test xax,xax
    jmp loop1b 
loop1:
        mov xcx, [esp+xax*@WordSize+28+25*4]
        mov dires[xax*@WordSize], xcx
        dec xax
loop1b:   
    jnz loop1
   
    SetObject xcx
    mov xdi, $ArgReg(pActionProc)
    mov ebx, [xcx].dCount
    mov xsi, [xcx].pItems
    ReleaseObject
   
    test ebx, ebx
    jmp loop0b
loop0a:
        mov xax, store
        test xax,xax
        jmp loop2b
    loop2:
             push dires[xax*@WordSize]
             dec xax
    loop2b:
        jnz loop2
       
        push [xsi]
        call PColProc ptr xdi
        mov xax, store
        shl xax, 2
        add xax, 4
        sub esp, xax
        add xsi, sizeof(POINTER)                            ;xsi -> Next item in the collection
        dec ebx
loop0b:
    jnz loop0a
MethodEnd

Regards, HSE.
Equations in Assembly: SmplMath

Biterider

Hi HSE
I think it will work in 32bit.  :thumbsup:
In 64bit the task is much more complicated, with many more instructions and therefore more CPU cycles to transfer the arguments, that I'm not sure it's wise to go that way. 
But as always, this has to be proven first, it is only a guess.

Biterider


HSE

Quote from: Biterider on November 01, 2023, 08:00:06 AMIn 64bit the task is much more complicated, with many more instructions and therefore more CPU cycles to transfer the arguments, that I'm not sure it's wise to go that way.

:thumbsup:
Equations in Assembly: SmplMath