News:

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

Main Menu

Dumb question: how to declare a nested structure?

Started by NoCforMe, April 22, 2015, 05:32:52 PM

Previous topic - Next topic

dedndave

all the links in the old forum that start with "masm32" must be edited to "masmforum"   :biggrin:

http://masmforum.com/board/index.php?topic=1700.msg17265#msg17265

jj2007

Yeah, we have aliens here, and they use time machines, too 8)
http://www.masmforum.com/board/index.php?topic=1700.0

nidud

#17
deleted

MichaelW

It does look like another MASM bug. At least for ML 6.14 and 6.15 DUP works as expected when it's embedded in the structure declaration.

;===============================================================================
include \masm32\include\masm32rt.inc
;===============================================================================
S1 STRUCT
    x DWORD ?
    y DWORD ?
S1 ENDS
S2 STRUCT
    s1 S1 2 dup(<>)
S2 ENDS
S3 STRUCT
    s2 S2 16 dup(<>)
S3 ENDS
;===============================================================================
.data
    s3 S3 <>
.code   
;=============================================================================== 
start:
;===============================================================================
    printf("%d\n\n",sizeof S3)
   
    mov   esi, alloc(sizeof S3)   
    mov   [esi].S3.s2.s1.x, 1
    mov   [esi].S3.s2.s1[8].x, 2   
    mov   [esi].S3.s2[32].s1.y, 3

    push  [esi].S3.s2.s1.x
    pop   s3.s2.s1.x
    push  [esi].S3.s2.s1[8].x   
    pop   s3.s2.s1[8].x   
    push  [esi].S3.s2[32].s1.y
    pop   s3.s2[32].s1.y
       
    printf("%d\n",s3.s2.s1.x)
    printf("%d\n",s3.s2.s1[8].x)
    printf("%d\n\n",s3.s2[32].s1.y)

    free  esi
    inkey
    exit
end start
;===============================================================================


00401021 C70601000000           mov     dword ptr [esi],1
00401027 C7460802000000         mov     dword ptr [esi+8],2
0040102E C7462403000000         mov     dword ptr [esi+24h],3
00401035 FF36                   push    dword ptr [esi]
00401037 8F0500304000           pop     [off_00403000]
0040103D FF7608                 push    dword ptr [esi+8]
00401040 8F0508304000           pop     [off_00403008]
00401046 FF7624                 push    dword ptr [esi+24h]
00401049 8F0524304000           pop     [off_00403024]



Well Microsoft, here's another nice mess you've gotten us into.

NoCforMe

Quote from: dedndave on April 23, 2015, 05:00:06 PM
you're right, it should be simple - lol

but, the work-around seems simple enough
i would guess you're going to be addressing with a register, anyways

[insert code example here]

at the end of the day, it's an array of 4-dword elements   :P

tomorrow, i'll see if i can figure out the syntax issue

Thanks. I'm going to go this route for now, as it's nice and simple (just have to remember to bunch the array elements in groups of 8 ). Yes, using a register to index them.

If someone figures out how to make MASM do this, cool. Will keep checking back here.
Assembly language programming should be fun. That's why I do it.

dedndave

Michael's solution in reply #18 looks like it has wheels   :t

i'd call that as near as it gets

$maxActiveItems EQU 16

$mhStruct STRUCT
  _handle HWND ?
  _flags DD ?
  _X DD ?
  _Y DD ?
$mhStruct ENDS

$moveHandleStruct STRUCT
  _mh $mhStruct 8 DUP(<>)
$moveHandleStruct ENDS

$HandleArray STRUCT
  $moveHandleStruct $maxActiveItems DUP(<>)
$HandleArray ENDS

    .DATA?

MoveHandles $HandleArray <>


i say Michael's - i guess it's an implementation of qWord's method that i linked earlier

MichaelW

Quote from: dedndave on April 24, 2015, 12:32:55 PM
i say Michael's - i guess it's an implementation of qWord's method that i linked earlier

I did mine at home where I don't currently have a working Internet connection (due to a hardware failure), and while I did not recall qWord's post, that could well be where the idea came from.
Well Microsoft, here's another nice mess you've gotten us into.