The MASM Forum

Miscellaneous => Irvine Book Questions. => Topic started by: TouEnMasm on April 18, 2021, 04:20:30 AM

Title: Multi dimensionnal structure and word multidimensional VARARG 64 32
Post by: TouEnMasm on April 18, 2021, 04:20:30 AM
There is two problems in the code below,DXVA.h
DXVA_PicEntry_H264 RefPicList[2][32];            a 2 * 32 structure  (DXVA_PicEntry_H264)
SHORT  Weights[2][32][3][2]                           a short de 2*32*3*2   
How To translate this in masm.
A soluce could be to change this in :
RefPicList DXVA_PicEntry_H264 64 dup (<>)
Weights WORD 384 dup(?)
Perhaps someone had a better soluce ?.




/* H.264/AVC picture entry data structure */
typedef struct _DXVA_PicEntry_H264 {
  union {
    struct {
      UCHAR  Index7Bits      : 7;
      UCHAR  AssociatedFlag  : 1;
    };
    UCHAR  bPicEntry;
  };
} DXVA_PicEntry_H264, *LPDXVA_PicEntry_H264;  /* 1 byte */

typedef struct _DXVA_Slice_H264_Long {
  UINT   BSNALunitDataLocation; /* type 1..5 */
  UINT   SliceBytesInBuffer; /* for off-host parse */
  USHORT wBadSliceChopping;  /* for off-host parse */

  USHORT first_mb_in_slice;
  USHORT NumMbsForSlice;

  USHORT BitOffsetToSliceData; /* after CABAC alignment */

  UCHAR  slice_type;
  UCHAR  luma_log2_weight_denom;
  UCHAR  chroma_log2_weight_denom;
  UCHAR  num_ref_idx_l0_active_minus1;
  UCHAR  num_ref_idx_l1_active_minus1;
  CHAR   slice_alpha_c0_offset_div2;
  CHAR   slice_beta_offset_div2;
  UCHAR  Reserved8Bits;
  DXVA_PicEntry_H264 RefPicList[2][32]; /* L0 & L1 */
  SHORT  Weights[2][32][3][2]; /* L0 & L1; Y, Cb, Cr */
  CHAR   slice_qs_delta;
                               /* rest off-host parse */
  CHAR   slice_qp_delta;
  UCHAR  redundant_pic_cnt;
  UCHAR  direct_spatial_mv_pred_flag;
  UCHAR  cabac_init_idc;
  UCHAR  disable_deblocking_filter_idc;
  USHORT slice_id;
} DXVA_Slice_H264_Long, *LPDXVA_Slice_H264_Long;


Title: Re: Multi dimensionnal structure and word
Post by: Biterider on April 18, 2021, 05:41:30 AM
Hi
I would say that
RefPicList DXVA_PicEntry_H264 64 dup (<>)
Weights WORD 384 dup(?)

is the right way to go

Biterider
Title: Re: Multi dimensionnal structure and word
Post by: TouEnMasm on April 18, 2021, 06:18:23 AM
In fact seem to be simple

RESINFO STRUCT
        Hfichier      dd  ?   ;            Handle de ressourcr
        Pfichier      dd  ?   ;             pointeur de ressource
        Tfichier      dd  ?   ;,            taille du fichier ressource
RESINFO  ENDS

Quote
qessai qword 8 dup (5 dup(30 dup(0)))
tabresinfo    RESINFO  8 dup (5 dup(30 dup(<>)))

sizeof qessai         9600       LENGTHOF 1200
sizeof tabresinfo   14400     LENGTHOF 1200

just stay a little question  :icon_idea: How to address that ????????
Title: Re: Multi dimensionnal structure and word
Post by: daydreamer on April 18, 2021, 06:48:07 AM
How to adress that?
Look help file for more high-level structure addressing
Structname.variablename
instead of keep track of the different offsets to different variables in struct
Multiple leas combined or mul? For adress?
Title: Re: Multi dimensionnal structure and word
Post by: HSE on April 18, 2021, 06:59:58 AM
Quote from: TouEnMasm on April 18, 2021, 04:20:30 AM

RefPicList DXVA_PicEntry_H264 64 dup (<>)
Weights WORD 384 dup(?)


More meaningfull is:


RefPicList DXVA_PicEntry_H264 2*32 dup (<>)
Weights WORD 2*32*3*2 dup(?)


In other way you are losing information and gaining nothing.

first position is a=0, b=0, c=0; last is a=8-1, b=5-1, c=30-1

(a*5*30+b*30+c)*8
(a*5*30+b*30+c)*12

Can you see that is more easy if declaration was 8*5*30?
Title: Re: Multi dimensionnal structure and word
Post by: Biterider on April 18, 2021, 03:39:14 PM
Hi
Quote from: HSE on April 18, 2021, 06:59:58 AM

RefPicList DXVA_PicEntry_H264 2*32 dup (<>)


Weights WORD 2*32*3*2 dup(?)
In other way you are losing information and gaining nothing.

That's right and is a better solution   :thumbsup:
I second that.

Biterider
Title: Re: Multi dimensionnal structure and word
Post by: TouEnMasm on April 18, 2021, 05:47:39 PM

This one seem to be working

Quote
;tabresinfo    RESINFO  8 dup (5 dup(30 dup(<>)))
;tabresinfo    RESINFO  Z dup (Y dup(X dup(<>))) >> Z=8,Y=5,X=30       
;
.const
   X equ 30
   Y equ 5
   Z equ 8
.data
tabresinfo    RESINFO  8 dup (5 dup(30 dup(<>)))

.code
;################################################################
GetXYZadress PROC  x:DWORD,  y:DWORD,  z:DWORD
   Local retour:DWORD
         mov adress,1
;effective adress = lea tabresinfo + offset
;offset for  x    @x = sizeof (RESINFO) * x     ;
;offset for  y   mean that x is full so @y = [sizeof (RESINFO) * X] * y
;offset for z    mean that y is full so @z = [[sizeof (RESINFO) * X] * Y] * z
;calcul
   ;x
   mov ecx,sizeof(RESINFO)    
   mov edx,0
   mov eax,x
   mul ecx
   mov adress,eax
   ;y
   mov ecx,sizeof(RESINFO)   
   mov edx,0
   mov eax,X
   mul ecx
   mov ecx,y
   mul ecx
   add adress,eax
   ;z
   mov ecx,sizeof(RESINFO)   
   mov edx,0
   mov eax,X
   mul ecx
   mov ecx,Y
   mul ecx
   mov ecx,z
   mul ecx
   add adress,eax   
   
   mov eax,offset  tabresinfo
   add eax,adress
         ret

GetXYZadress endp

;################################################################
Title: Re: Multi dimensionnal structure and word
Post by: daydreamer on April 18, 2021, 08:19:27 PM
Not tested to do it SIMD

Movups xmm0,xyz
Movd xmm1, sizeof(resinfo)
Shufps xmm1,xmm1,all ; constant that shuffles. To all 4
Pmuludq xmm0,xmm1
Movaps addresses,xmm0
Movd eax,xmm0
Add eax,[addresses+4]
Add eax,[addresses+8]
Title: Re: Multi dimensionnal structure and word
Post by: HSE on April 19, 2021, 09:06:20 AM
Quote from: daydreamer on April 18, 2021, 08:19:27 PM
Not tested

Naturally. Nice final, but main part is missing  :biggrin:
Title: Re: Multi dimensionnal structure and word
Post by: TouEnMasm on April 19, 2021, 04:26:50 PM
Here the c method


long long contenu [5][10][16];
long long essai;
int main()
{
essai = 555;
printf(" size : %u \n",sizeof contenu);
contenu[3][5][8] = essai;
printf(" [3][5][8] : %llu \n",contenu[3][5][8]);
_getch();
    return 0;



Quote
_main:
  00000000: 55                 push        ebp
  00000001: 8B EC              mov         ebp,esp
  00000003: 83 EC 40           sub         esp,40h
  00000006: 53                 push        ebx
  00000007: 56                 push        esi
  00000008: 57                 push        edi
  00000009: 33 C0              xor         eax,eax
  0000000B: C7 05 00 00 00 00  mov         dword ptr [?essai@@3_JA],22Bh
            2B 02 00 00
  00000015: A3 04 00 00 00     mov         dword ptr [?essai@@3_JA+4],eax        ;load qword essai
;--------------------------------------------------------------------------------------------------------
  0000001A: 68 00 19 00 00     push        1900h
  0000001F: 68 00 00 00 00     push        offset ??_C@_0N@KJIMBLEH@?5size?5?3?5?$CFu?5?6@
  00000024: E8 00 00 00 00     call        _printf
  00000029: 83 C4 08           add         esp,8
;------------------------------------------------------------------------------------------------------------
  0000002C: B8 00 05 00 00     mov         eax,500h   
                    imul        ecx,eax,3               ;result ecx ? [3][5][8]
  00000034: BA 80 00 00 00     mov         edx,80h
  00000039: 6B C2 05           imul        eax,edx,5
  0000003C: 8D 8C 01 00 00 00  lea         ecx,?contenu@@3PAY19BA@_JA[ecx+eax]
            00
  00000043: BA 08 00 00 00     mov         edx,8
  00000048: C1 E2 03           shl         edx,3
  0000004B: A1 00 00 00 00     mov         eax,dword ptr [?essai@@3_JA]
  00000050: 8B 35 04 00 00 00  mov         esi,dword ptr [?essai@@3_JA+4]
  00000056: 89 04 11           mov         dword ptr [ecx+edx],eax
  00000059: 89 74 11 04        mov         dword ptr [ecx+edx+4],esi
  0000005D: B8 00 05 00 00     mov         eax,500h
  00000062: 6B C8 03           imul        ecx,eax,3
  00000065: BA 80 00 00 00     mov         edx,80h
  0000006A: 6B C2 05           imul        eax,edx,5
  0000006D: 8D 8C 01 00 00 00  lea         ecx,?contenu@@3PAY19BA@_JA[ecx+eax]
            00
  00000074: BA 08 00 00 00     mov         edx,8
  00000079: C1 E2 03           shl         edx,3
  0000007C: 8B 44 11 04        mov         eax,dword ptr [ecx+edx+4]
  00000080: 50                 push        eax
  00000081: 8B 0C 11           mov         ecx,dword ptr [ecx+edx]
  00000084: 51                 push        ecx
  00000085: 68 00 00 00 00     push        offset ??_C@_0BE@EALIJHLA@?5?$FL3?$FN?$FL5?$FN?$FL8?$FN?5?3?5?$CFllu?5?6@
  0000008A: E8 00 00 00 00     call        _printf
  0000008F: 83 C4 0C           add         esp,0Ch
  00000092: FF 15 00 00 00 00  call        dword ptr [__imp___getch]
  00000098: 33 C0              xor         eax,eax
  0000009A: 5F                 pop         edi
  0000009B: 5E                 pop         esi
  0000009C: 5B                 pop         ebx
  0000009D: 8B E5              mov         esp,ebp
  0000009F: 5D                 pop         ebp
  000000A0: C3                 ret
500h = 10*16*8 = 1280 = 500h  ;...




Title: Re: Multi dimensionnal structure and word
Post by: jj2007 on April 19, 2021, 05:35:06 PM
Quote from: daydreamer on April 18, 2021, 08:19:27 PM
Not tested to do it SIMD

Movups xmm0,xyz
Movd xmm1, sizeof(resinfo)

This is so advanced that my old debugger doesn't recognise it! Really, you should test it:
include \masm32\include\masm32rt.inc
.686p
.xmm
.data
resinfo dq 123
.code
start:
  int 3
  nops 2
  movd xmm1, sizeof(resinfo)
  nops 4
  invoke ExitProcess, 0
end start

CPU Disasm
Address   Hex dump          Command                                  Comments
00401000   .  CC            int3
00401001   .  90            nop
00401002   .  90            nop
00401003   .  660F6EC8      movd xmm1, eax
00401007      08            db 08                                    ; Backspace
00401008      90            nop
00401009      90            nop
0040100A      90            nop
0040100B      90            nop
0040100C  /.  6A 00         push 0                                   ; /ExitCode = 0
0040100E  \.  E8 01000000   call <jmp.&kernel32.ExitProcess>         ; \KERNEL32.ExitProcess
Title: Re: Multi dimensionnal structure and word
Post by: daydreamer on April 19, 2021, 07:22:46 PM
Quote from: HSE on April 19, 2021, 09:06:20 AM
Quote from: daydreamer on April 18, 2021, 08:19:27 PM
Not tested

Naturally. Nice final, but main part is missing  :biggrin:
I was thinking of fetch from adress where x:dword, Y:dword, Z:dword is
But anyway multiply every time is inefficient, TouEnMasm would be good to store 3 constants somewhere so you can add pointer,xconstant when in innerloop for increment x or y or Z pointer,which is faster
Title: Re: Multi dimensionnal structure and word
Post by: HSE on April 19, 2021, 09:50:16 PM
Quote from: jj2007 on April 19, 2021, 05:35:06 PM
This is so advanced that my old debugger doesn't recognise it! Really, you should test it:

  ...
  movd xmm1, sizeof(resinfo)
  ...

:biggrin: That it's not a valid instruction!

Must use a GPR:

   mov eax, 8
   movd xmm1, eax


JJ: your assembler is half smart, it write sizeof(resinfo) but in a wrong place  :biggrin: 

Title: Re: Multi dimensionnal structure and word multidimensional
Post by: TouEnMasm on August 05, 2021, 07:13:23 PM
Hello,
Here a soluce in 32 bits for creating multidimesionnal array of 2,3,4 dimensions.
Usage is simple:

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,lpCmdLine:XMASM,nShowCmd:DWORD
Local ppcallback:DWORD,ppath,pstarwar
;---- invoke caller,essai         ok
mov ppath,CREATEMULTI (byte,20,MAX_PATH) ;2 dimensions ,classic array of path
mov pstarwar,CREATEMULTI (QWORD,5,5,10,10) ;4 dimensions
mov edx,MAX_PATH
invoke GetMultiAddr,ppath,3,0     ;le 4eme chemin
;edx = adresse

invoke GetMultiAddr,pstarwar,3,0,1,0
;invoke GetMultiAddr,ptableau,5,0

mov eax,0
ret
WinMain endp



GetMultiAddr, is a c proc using VARARG ,perhaps he need to be improve
There is also in the source a CALLBACK MACRO.



Title: Re: Multi dimensionnal structure and word multidimensional
Post by: HSE on August 05, 2021, 10:35:54 PM
Hi Yves!

     Look so much code for so little.
     Anyway still I can't make to work in Masm32.  :biggrin:

     if is working how you wanted: Fantastic  :thumbsup:
     
Title: Re: Multi dimensionnal structure and word multidimensional
Post by: TouEnMasm on August 06, 2021, 12:19:28 AM
I have made the test with ML and the masm32 package.
It is as usual,the many limitations of ML don't allow to do what is perfectly correct.
Use UASM,JWASM or ASMC,I have not tested,but i am sure they work.
Five minutes later,I have tested UASM,JWASM,ASMC all three are happy with the code.
You have the choice.
Title: Re: Multi dimensionnal structure and word multidimensional
Post by: HSE on August 06, 2021, 08:32:26 AM
Then, for sure, I maked something wrong   :biggrin:
:thumbsup:
Title: Re: Multi dimensionnal structure and word multidimensional
Post by: LiaoMi on August 07, 2021, 04:08:13 AM
Hi TouEnMasm,

some ideas can be seen here: 2.2.2.1: HLA Array Types
https://www.plantation-productions.com/Webster/Win32Asm/WindowsAsmPgm/html/Ch02.html

Using SIMD to Optimize x86 Assembly Code in Array Sum Example
https://www.codeproject.com/Articles/5298048/Using-SIMD-to-Optimize-x86-Assembly-Code-in-Array

SETL (SET Language) is a very high-level programming language based on the mathematical theory of sets. It was originally developed by (Jack) Jacob T. Schwartz at the New York University (NYU) Courant Institute of Mathematical Sciences in the late 1960s.
https://en.wikipedia.org/wiki/SETL


INCLUDE Irvine32.inc
INCLUDE Macros.inc

.data
MAX_ROWS = 5                                            ; constant for num rows
MAX_COLS = 5                                            ; constant for num cols

my2DArray dword MAX_ROWS * MAX_COLS dup(0)                ; creates 2-d array
spaceStr byte " ",0                                        ; for displaying a space
inputRow byte "Enter Row(Type 99 To Exit): ",0            ; for displaying massage for entering a Row
inputColumn byte "Enter Column:",0                        ; for displaying massage for entering a Col
currentValue byte "The daisies there was:",0            ; for displaying massage for a Current value
inputValue byte "Daisies Gathered:",0                    ; for displaying massage for entering a New Valuse
Bye byte "Have a Wonderful Day!!!",0                    ; Displaying Have a wonderful day massage
displayHeader byte "Filed of Daisies:",0                ; string to display before report

mainPoint dword ?
randRow dword ?                                            ; holds random row
randCol dword ?                                            ; holds random row
randValue dword ?                                        ; holds random value to assign into array
replaceRow dword ?                                        ; holds the replaced Row
replaceColumn dword ?                                    ; holds the replaced Column
newValue dword ?                                        ; holds the new value


multiply dword 8                                        ;
divide dword 10
addnum sdword 0                                            ; add # for Row
addnumc sdword 0                                        ; add # for Column


.code
main PROC
    CALL Clrscr
    CALL randomize                    ; stir the pot

                           
                             
    MOV ECX, MAX_ROWS * MAX_COLS    ; Move 2-D array to ECX
    MOV EDI, offSet my2DArray        ; display prompt 2-D array

genLoop:
   
    MOV EAX, 100                    ; load EAX with upper bound for random value
    CALL randomRange                ; generate random value 0..upper bound-1
    MOV randValue, EAX
    MOV [EDI], EAX
    add EDI, type my2DArray            ; edi is to stick value into array
   

    loop genLoop


SecondLoop:
    Call crlf
   
    Call crlf
    mWrite "Filed of Daisies:"       
    Call crlf
    Call crlf
                                    ; at this point my2DArray is full of 0s
                                    ; call proc to display array
    CALL displayMy2DArray                               
   
   
    MOV EDX, offset inputRow        ; display prompt inputRow
    CALL writestring                ; display input Row message
    CALL readDec                    ; display random row
    MOV replaceRow, EAX                ; store random # into randRow
       
    CMP replaceRow, 99                ; quit the program when typing # 99
    JE TakeCare                        ; get number
    MOV randRow, EAX                ; store in memory

    MOV EDX, offset inputColumn        ; display prompt inputColumn
    CALL writestring                ; display input Column
    CALL readDec                    ; get number
    MOV replaceColumn, EAX            ; store in memory

    CALL CRLF                        ;\n
   

    MOV EDX, offset currentValue    ; display prompt currentValue
    CALL writestring                ; display Currently the value message
    MOV EAX, replaceRow                ; get number
    MOV EBX, replaceColumn            ; store in memory

    CALL getElementOfArray            ; get element at  [replaceRow][replaceColumn] to newValue
    CALL WriteDec                    ; display get element of array
    CALL CRLF                        ;\n
   
   
   
   
    ;;;;;;;;;;;
    ;=============================
    ; Multiplication
    ;=============================
;    mov edx, 0                                    ; 0 out edx in preparation for iMul
;    MOV EAX, replaceRow                ; get number
;    MOV EBX, replaceColumn            ; store in memory
;
;    fld    multiply
;    fmul
;    fst    newValue
;                                        ; eax*ebx ==> edx:eax contains product
;    mov newValue, eax                            ; hold on to product                   
;
;    ;=============================
;    ; divition
;    ;=============================
;    MOV EAX, replaceRow                ; get number
;    MOV EBX, replaceColumn            ; store in memory
;
;    cdq                                            ; prepares edx: eax iDiv
;
;    ;iDiv eax                                    ; eax/ebx ==> edx:eax contains quotient, edx
;    mov divide, eax                            ; hold on to quotient
;    MOV newValue, EAX                ; store in memory
;    mov mainPoint, edx                            ; hold on to remainder


    ;;;;;;;;;;
   
    MOV EDX, offset inputValue        ; display prompt inputValue
    CALL writestring                ; display input Value message
    CALL readDec                    ; get number
    MOV newValue, EAX                ; store in memory
   
    MOV EAX, replaceRow                ; load eax with new added row
    MOV EBX, replaceColumn            ; load ebx with new added column
    MOV ECX, newValue                ; load ecx with new added value
    ;CALL WriteDec   
       
   
   
                           
    CALL setElementOfArray            ; set element at [replaceRow][replaceColumn] to newValue

   
    JMP SecondLoop                    ; Jump the second loop to TakeCare
   

TakeCare:


CALL CRLF                            ;\n
MOV EDX, offset Bye                    ; display prompt Good Bye message
CALL writestring                    ; display Good Bye message
CALL CRLF                            ;\n

    exit
main ENDP
        ; =============================================
        ; setElementOfArray procedure expects 3 parameters
        ;    EAX row
        ;    EBX col
        ;    ECX value
        ;
        ;  logiCALLy this will be like:  my2DArray[EAX,EBX]=ECX
setElementOfArray PROC uses EDX EDI

    MOV EDX, 0                ; prepare for mul

    push EBX                ; put EBX the column on the stack

    MOV EBX, MAX_COLS*4        ; calculate the number of bytes in a row
                            ; since EAX has the rowNum
    mul EBX                    ; EAX is now rowNum * MAX_COLS*4 - total bytes before current row
    MOV EDI, EAX            ; put byte offset into EDI

    pop EAX                    ; we had put EBX on the stack which was the colNum
                            ; put that on EAX

    MOV EBX, 4                ; load EBX with 4 for size of element
    mul EBX                    ; EAX is now colNum*4 which is the byte offset in the current row
    add EDI, EBX            ; EDI is now rowNum * MAX_COLS*4 + colNum*4
   
   
                            ; which is the byte offset from the beginning
                            ; of the array to this element rowNum,colNum
   

    MOV my2DArray[EDI], ECX      ; stick value in ECX into array
    mov ecx, 0
    MOV multiply, eax
    mul edi
   
                            ; phew!
    ret
setElementOfArray ENDP

        ; =============================================
        ; displayMy2DArray procedure expects no parameters
        ;       
displayMy2DArray PROC uses EDX EDI ECX EAX

    mov ecx, MAX_COLS                    ; move ecx to coulmn
    push eax
    mov eax, 0
    mWrite "      "                        ; Sapce
    call padOnLeft
dispCol:                                ; display Column Numbers
    call writeDec
    mWrite "  "                            ; Sapce
    call padOnLeft                        ; pad with spaces
    inc eax
    loop dispCol

    call crlf                            ;\n
    pop eax

    mov ecx, MAX_COLS
    mov eax, 0
    mWrite "    "                        ; Sapce
    call padOnLeft                        ; pad with spaces
UnderLine:
    mWrite " ---- "                        ; line of the col
    loop UnderLine                       
    call crlf                            ;\n

    mov edi, 0                            ; load edi with 0 offset

    mov ecx, MAX_ROWS                    ; load ecx with number of rows so we can loop through rows

displayRow:                                ; top of outerloop on rows
   
    Mov eax, addnum
    call padOnLeft
    call writedec   
    inc addnum
   
    mWrite" :"
    push ecx                            ; preserve ecx from outloop to use innerloop

    mov ecx, MAX_COLS                    ; load ecx with number of cols so we can loop through cols
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
displayCol:                                ; top of innerloop on cols
    mov eax, my2DArray[edi]                ; move element from array to eax for display
    mWrite " "
    call padOnLeft                        ; pad with spaces
   
                                        ; for debugging purposes show . instead of 0
                        ; display .
       

    .if EAX == 0                        ;  if element to display is 0
        push EAX                        ; preserve EAX
        MOV al, '.'                        ; display .
        CALL writeChar
        pop EAX                            ; restore EAX
    .else
        CALL writedec                    ; display element
    .endIf

    ;call desplayCarret

    MOV EDX, offset spaceStr        ; display a space
        CALL writestring                    ; display element
   

    add EDI,4                            ; advance dsi to next element

   
    loop displayCol                        ; bottom of innerloop (loop on cols)

   
    CALL CRLF                            ; now that a row has been displayed, MOVe to beginning of next line for next row

    pop ECX                                ; restore ECX for outerloop on rows

    loop displayRow                        ; bottom of outerloop (loop on rows)
       
   

    mov addnum, 0                        ; Start with 0 # Row
    mov addnumc, 0                        ; Start with 0 # Column

    ret                                    ; done with this method
displayMy2DArray ENDP

        ; =============================================
        ; padOnLeft procedure expects 1 parameters
        ;        EAX with value to pad
        ;       
padOnLeft PROC uses EDX

    .if EAX < 1000
        MOV EDX, offset spaceStr            ; display space
        CALL writestring
    .endif

    .if EAX < 100
        MOV EDX, offset spaceStr            ; display space
        CALL writestring
    .endif

    .if EAX < 10
        MOV EDX, offset spaceStr            ; display space
        CALL writestring
    .endif
           
    ret
padOnLeft ENDP
        ; =============================================
        ;    getElementOfArray procedure expects 2 parameters
        ;    EAX row
        ;    EBX col
        ;
        ;  logiCALLy this will be like:  my2DArray[EAX,EBX]=ECX
getElementOfArray PROC
   
    MOV EDX, 0                ; prepare for mul

    push EBX                ; put EBX the column on the stack

    MOV EBX, MAX_COLS*4        ; calculate the number of bytes in a row
                            ; since EAX has the rowNum
    mul EBX                    ; EAX is now rowNum * MAX_COLS*4 - total bytes before current row
    MOV EDI, EAX            ; put byte offset into EDI

    pop EAX                    ; we had put EBX on the stack which was the colNum
                            ; put that on EAX

    MOV EBX, 4                ; load EBX with 4 for size of element
    mul EBX                    ; EAX is now colNum*4 which is the byte offset in the current row
    add EDI, EAX            ; EDI is now rowNum * MAX_COLS*4 + colNum*4
   
                            ; which is the byte offset from the beginning
                            ; of the array to this element rowNum,colNum
   
    MOV EAX, my2DArray[EDI]      ; stick value in EAX into array
   
                           
    ret                        ; Return
getElementOfArray ENDP
Title: Re: Multi dimensionnal structure and word multidimensional
Post by: TouEnMasm on August 07, 2021, 08:11:59 PM
Hello,
The vararg for 32 bits seem solved.
I try now to do the same thing for 64 bits.
I there is no more than four argument,no problem they are in rcx, rdx, r8, et r9.
A little help is needed for the five,six .. arguments,They are in stack ,How find the them ?
Title: Re: Multi dimensionnal structure and word multidimensional
Post by: TouEnMasm on August 07, 2021, 10:58:32 PM
solved also The 64 bits form
I have tested it with uasm,jwasm and asmc64.
Little modifies  :toothy: made.The X64 and X32 directories give the two samples.
Take care that uasm dont find the fifty element at the same place    (64 bits sample debut.asm)

.If NBdim == 4
mov rdx,0
mov ecx,[rbx+12]
.if ecx == 0
jmp NullDim
.endif
;mov eax,[rbp+50h]                                           ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< uasm
mov         eax,dword ptr [rbp+30h]                       ;<<<<<<<<<<<<<<<< jwasm ,asmc64
mul ecx
add cumul,eax
.endif