News:

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

Help with initalizing STRUC please

Started by cobold, September 01, 2010, 10:06:39 AM

Previous topic - Next topic

cobold

Hello,

if I initialize a STRUCTURE variable in the DATA section, it seems that only the first value is set and all other elements are ZERO.
But if I move a value in the CODE section, it works.


MaxNbr EQU 64

big STRUC
dwSize DWORD ?
Element DWORD MaxNbr dup(?)
big ends

.data
big_test big <2>,<100>,<101>

start:

;mov big_hundert.Element[0],100
print "Size "
print str$(big_test.dwSize),13,10,13,10     ; this is 1 as expected

xor ebx,ebx
.while ebx < big_test.dwSize
print "Element "
print str$(ebx), " = "
print str$(big_test.Element[ebx]),13,10     ; this is 0 but with mov big_hundert.Element[0],100 is set correctly
inc ebx
.endw




jj2007


cobold

Thanks for the help, solved it in the meantime.
Have to initialize with

<2, {100,101}


jj2007

Interesting. Both versions work:
Quoteinclude \masm32\include\masm32rt.inc
MaxNbr  EQU 64

big STRUC
   dwSize DWORD ?
   Element DWORD MaxNbr dup(?)
big ends

.data
; big_test big <2, {100, 101, 102, 103}>  ; OK
big_test big <2, <100, 101, 102, 103>>

.code
start:
   print str$(big_test.Element[0]), 13, 10
   print str$(big_test.Element[4]), 13, 10
   print str$(big_test.Element[8]), 13, 10
   exit

end start

clive

Or for multiples

big_test big {2, {100, 101}}, {3, {200, 201, 202}}
         big {4, {300, 301, 302, 303}}
It could be a random act of randomness. Those happen a lot as well.

zemtex

I have a similar question. How do you declare a buffer of structs / an array of structs like you do with normal data sizes. Example: Number db 8 dup 10
How do you declare such an array with a struct?  :P
I have been puzzling with lego bricks all my life. I know how to do this. When Peter, at age 6 is competing with me, I find it extremely neccessary to show him that I can puzzle bricks better than him, because he is so damn talented that all that is called rational has gone haywire.