News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Array macros

Started by HSE, February 03, 2020, 08:17:46 AM

Previous topic - Next topic

HSE

Hi all!

I'm translating some basic programs and remembering how easy was to write matrices  :biggrin:

To simulate that writing I have modified a macro contained in RadAsm package that perhaps is from bitRAKE:
DIM_MASTER macro mod1, nombre, tipo, dimensions:VARARG
   local value1
   value1 textequ <1>
   count = 0
    FOR dimension, <&dimensions>
        value1 CATSTR value1 , <*>, %dimension
    ENDM
    if mod1 eq 0
        nombre&_mtx &tipo value1 dup (?)
    else
        nombre&_mtx &tipo value1 dup (<?>)
    endif

   &nombre MACRO dimensionsn:VARARG
        LOCAL count,dwidth,dist, hayc, hayv,dwidth2

        count = 0
        dwidth = 1
        dist = 0
        hayc = 0
        hayv = 0

        FOR arg,<&dimensionsn>
            oa = OPATTR arg
            if oa and 0100b
                hayc = 1
            else
                hayv = 1
            endif
        ENDM
        if hayv
            mov eax, 0
        endif
        FOR arg,<&dimensionsn>
            count = count + 1
            oa = OPATTR arg
            if oa and 0100b
                dwidth = dwidth2 * TYPE nombre&_mtx
                dist = dist + (arg * dwidth2)
            else
                push eax
                ;; Should test that arg is constant, output code
                mov eax, arg
                mov ecx, dwidth
                mul ecx       
                pop ecx
                add eax, ecx
            endif
            dwidth = dwidth * @ArgI(%count, dimensions)
        ENDM
         if hayv and hayc
            if mod1 eq 0   
                EXITM @CatStr(&nombre,<_mtx>,<[>,eax * TYPE nombre&_mtx+ %dist ,<]>)
            else
                mov ecx, TYPE nombre&_mtx
                mul ecx
                EXITM @CatStr(&nombre,<_mtx>,<[>,eax + %dist ,<]>)
            endif
        elseif hayv   
           if mod1 eq 0   
                EXITM @CatStr(&nombre,<_mtx>,<[>,eax * TYPE nombre&_mtx ,<]>)
            else
                mov ecx, TYPE nombre&_mtx
                mul ecx
                EXITM @CatStr(&nombre,<_mtx>,<[>,eax,<]>)
            endif
         elseif hayc
            EXITM @CatStr(&nombre,<_mtx>,<[>, %dist ,<]>)
        endif

    ENDM

endm

DIM macro nombre, tipo, dimensions:VARARG
%    DIM_MASTER 0, nombre, tipo, <dimensions>
ENDM

DIMS macro nombre, tipo, dimensions:VARARG
%    DIM_MASTER 1, nombre, tipo, <dimensions>
ENDM


Arrays of variables (DIM) or structures (DIMS) are allowed. Declaration and use is simple:
DIM nmanning, Real8, 3, 3, 50
DIM clase, DWORD, 3, 3, 50
DIMS cruce, cross, 3

use:
mov clase(0, 0, 1) , 1
fSlv8 distacross(0, 0, 1) = 129
fSlv8 profacross(0, 0, 1) = referenciaaltura - cruce(0).elevation + 1.5
fSlv8 nmanning(0, 0, 1) = 0.06

mov cruce(0).nstages , 1
fSlv8 cruce(0).primario.lengthChannel = (250 + 400) / 2
fSlv8 cruce(0).primario.lengthPlain = (250 + 400) / 2
fSlv8 cruce(0).primario.slope = 0.005


But there is some problems of early expansion. Some are solved postponing expansion, others with a wrapper, but in SmplMath look that there is no solution:

nice but don't work:
fSlv8 reservorio(v1, 2) = reservorio(v1, 0) - reservorio(@fSlvI(v1 - 1), 0)

this work:
        fld reservorio(v1, 0)
        fsub reservorio(@fSlvI(v1 - 1), 0)
        fstp reservorio(v1, 2)
     


There is no problem with fixed elements matrix(4, 15)  but with variables matrix( x, 4, y)
Ideas are welcome!

Later: some little mistake corrected.
Later2: a correction for structures array

Following the project (ObjAsm32 & SmplMath, assembled with AsmC) [binary is using DebugCenter as interface]:
Equations in Assembly: SmplMath