The MASM Forum

General => The Campus => Topic started by: zin on March 30, 2020, 06:05:44 PM

Title: Having trouble aligning an array of structures
Post by: zin on March 30, 2020, 06:05:44 PM
hello, i have problem i try to align array of structures but it's dosen't work ,
when i look at the memory window in debugging i see the values are not align

MyStruct STRUCT
   
    field1 WORD ?
    align DWORD
    field2 DWORD 20 DUP(?)

MyStruct ENDS

.data
   
    hello MyStruct 20 dup (<2,20 DUP (4)>)


but when i declare only one veriable of structurs it does, why is it happening somebody know ? :undecided:

MyStruct STRUCT
   
    field1 WORD ?
    align DWORD
    field2 DWORD 20 DUP(?)

MyStruct ENDS

.data
   
    hello MyStruct <2,20 DUP (4)>

Title: Re: Having trouble aligning an array of structures
Post by: hutch-- on March 30, 2020, 06:13:37 PM

MyStruct STRUCT DWORD
...
MyStruct ENDS

With WORD sized members, either pair them or add padding.
Title: Re: Having trouble aligning an array of structures
Post by: zin on March 30, 2020, 06:27:28 PM
Thank you for the quick response,
I added what you wrote but it still doesn't work

MyStruct STRUCT DWORD
   
    field1 WORD ?
    align DWORD
    field2 DWORD 20 DUP(?)

MyStruct ENDS
Title: Re: Having trouble aligning an array of structures
Post by: hutch-- on March 30, 2020, 07:26:50 PM

MyStruct STRUCT DWORD
    field1 dw ?
    dummy dw ?
    field2 DWORD 20 DUP(?)
MyStruct ENDS
Title: Re: Having trouble aligning an array of structures
Post by: _japheth on March 30, 2020, 08:12:57 PM
Quote from: zin on March 30, 2020, 06:05:44 PM
hello, i have problem i try to align array of structures but it's dosen't work ,
when i look at the memory window in debugging i see the values are not align

Might very well be a debugger problem. You can verify the correct size by adding:


        mov eax,sizeof hello


and then examine the listing file; eax should be loaded with 690h, which is 1680 decimal.

EDIT: perhaps this is indeed a Masm bug. The listing looks ok, but the object module, at least for output format -coff and Masm v8, looks not ok

You can verify this yourself with: DUMPBIN /rawdata <filename>.obj

Workaround: use jwasm/uasm/...
Title: Re: Having trouble aligning an array of structures
Post by: zin on March 30, 2020, 09:50:18 PM
Quote from: _japheth on March 30, 2020, 08:12:57 PM
Quote from: zin on March 30, 2020, 06:05:44 PM
hello, i have problem i try to align array of structures but it's dosen't work ,
when i look at the memory window in debugging i see the values are not align

Might very well be a debugger problem. You can verify the correct size by adding:


        mov eax,sizeof hello


and then examine the listing file; eax should be loaded with 690h, which is 1680 decimal.

EDIT: perhaps this is indeed a Masm bug. The listing looks ok, but the object module, at least for output format -coff and Masm v8, looks not ok

You can verify this yourself with: DUMPBIN /rawdata <filename>.obj

Workaround: use jwasm/uasm/...

I'm pretty new in the field so I still don't know what you mean by that:

  "You can verify this yourself with: DUMPBIN /rawdata <filename>.obj

Workaround: use jwasm/uasm/...".


But yes I check by the sizeof and I see that the size it catches is correct.
thenk you!
Title: Re: Having trouble aligning an array of structures
Post by: zin on March 30, 2020, 09:57:32 PM
Quote from: hutch-- on March 30, 2020, 07:26:50 PM

MyStruct STRUCT DWORD
    field1 dw ?
    dummy dw ?
    field2 DWORD 20 DUP(?)
MyStruct ENDS


like this its look ok thenk you :thup: