News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

defining nested structures

Started by UlliN, December 15, 2009, 11:12:25 AM

Previous topic - Next topic

UlliN

Hello,

I've got some problems defining nested structures.
Perhaps someone can show/explain, how to define such a multi-dim-structure and how to access the elements.
The example is written in COBOL-Syntax, but I hope it's understandable.
Unfortunately my MASM-Translation doesn't work :-(

Thank you in advance
Ulli





; Definition of a 10x10 (11x11) Matrix, each element consists of 2 variables
; Each Row and each Column is preceeded by a counter
;  COBOL-Syntax
;     01 Matrix.
;        02 RowCount  long.   
;        02 Row       occurs 10.
;           04 ColCount  long.
;           04 Col       occurs 10.
;              06 F1     long.
;              06 F2     long.
;
;     move 1 to F1(1, 1)



    .data
       Col struct
         f1  dd ?
         f2  dd ?
       Col ends

       Row struct
         ColCount  dd ?
         CX          Col 10 dup <>
       Row ends

       Matrix struct
         RowCount  dd ?
         RX            Row 10 dup <>
       Matrix ends

       M Matrix <>
    .code

    mov M.RX.CX.f1, 1


TNick

CX is a register. Change that to _CX_, for example.
you also need to enclose <> in () like in
_CX_ Col 10 dup (<>)

Nick

UlliN

Hi Nick,
thank you for the hint  "(<>)"  ! That works.

But how can I access the elements ?

"mov M.R(eax).C_(ecx).f1, 1"   doesnt work ;-(


Ulli

TNick

:)

    mov M.RX[0 * (SIZEOF Row)]._CX[0 * (SIZEOF Col)].f1, 1
    mov M.RX[0 * (SIZEOF Row)]._CX[0 * (SIZEOF Col)].f2, 2
    mov M.RX[0 * (SIZEOF Row)]._CX[1 * (SIZEOF Col)].f1, 3
    mov M.RX[0 * (SIZEOF Row)]._CX[1 * (SIZEOF Col)].f2, 4
    mov M.RX[0 * (SIZEOF Row)]._CX[8 * (SIZEOF Col)].f1, 1
    mov M.RX[0 * (SIZEOF Row)]._CX[8 * (SIZEOF Col)].f2, 2
    mov M.RX[0 * (SIZEOF Row)]._CX[9 * (SIZEOF Col)].f1, 3
    mov M.RX[0 * (SIZEOF Row)]._CX[9 * (SIZEOF Col)].f2, 4
   
    mov M.RX[9 * (SIZEOF Row)]._CX[0 * (SIZEOF Col)].f1, 1
    mov M.RX[9 * (SIZEOF Row)]._CX[0 * (SIZEOF Col)].f2, 2
    mov M.RX[9 * (SIZEOF Row)]._CX[1 * (SIZEOF Col)].f1, 3
    mov M.RX[9 * (SIZEOF Row)]._CX[1 * (SIZEOF Col)].f2, 4
    mov M.RX[9 * (SIZEOF Row)]._CX[8 * (SIZEOF Col)].f1, 1
    mov M.RX[9 * (SIZEOF Row)]._CX[8 * (SIZEOF Col)].f2, 2
    mov M.RX[9 * (SIZEOF Row)]._CX[9 * (SIZEOF Col)].f1, 3
    mov M.RX[9 * (SIZEOF Row)]._CX[9 * (SIZEOF Col)].f2, 4

And, if you need to use registers, recall that you need to get back, in the end, at something like:
   mov   dword ptr [eax + edx*4 + 5],   edx
that is: [BASE + INDEX*SCALE + OFFSET]

Regards,
Nick