flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Aligned structures using "struc" |
Author |
|
vid 03 Feb 2007, 20:39
(repost from here)
recently i had funny alignment problem with FASM. I had structure, let's say STRUC1 Code: struc STRUC1 x,y,z{ .x dd x+0 .y dd y+0 .z db z+0 } I wanted to align it Code: struc STRUC1 x,y,z{ .x dd x+0 .y dd y+0 .z db z+0 align 4 ;<---- } This worked nicely, structure size was aligned. Later, I "overloaded" it with STRUC2: Code: struc STRUC2 x,y,z,xx,yy,zz{ . STRUC1 x,y,z .xx dd xx+0 .yy dd yy+0 .zz db zz+0 align 4 } This seemed to work too, until once i found that some data of intialized STRUC2 structure were shifted by two bytes against where they should be. It took me nearly hour and half to realize what is happening: the initialized structure was being declared on unaligned offset. so the resulting declaration (after preprocessing of struct) looked like: Code: ; jano STRUC2 1,2,3,4,5,6 jano: .x dd 1 .y dd 2 .z db 3 align 4 .xx dd 4 .yy dd 5 .zz db 6 align 4 first members of structure were declared unaligned, until first align was reached. So for every structure with aligned members in FASM, also align the structure itself, like this: Code: struc STRUC1 x,y,z{ align 4 .: .x dd x+0 .y dd y+0 .z db z+0 align 4 } but of course, it's always better to use standard STRUCT macros. |
|||
03 Feb 2007, 20:39 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.