This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
aligning_20structures [2018/04/17 15:01] tbest3112 Added syntax highlighting |
aligning_20structures [2021/12/04 16:05] (current) richardrussell Modified for 64-bit compatibility |
||
---|---|---|---|
Line 6: | Line 6: | ||
<code bb4w> | <code bb4w> | ||
DIM mystruct{member1, member2, etc, padding%} | DIM mystruct{member1, member2, etc, padding%} | ||
- | !(^mystruct{}+4) = (mystruct{}+4) AND -8 | + | PTR(mystruct{}) = PTR(mystruct{}) AND -8 |
</code> | </code> | ||
When the structure is declared, a dummy member **padding%** is added at the very end; this allows the structure to be moved up in memory by 4 bytes, if necessary, without corrupting subsequent memory contents; //it is vitally important that this member is never written//! The second line adjusts the address of the structure so that it is a multiple of eight.\\ \\ If you want to align the structure at a multiple-of-16 address the padding needs to be 12 bytes in size, most easily arranged by making it an array:\\ | When the structure is declared, a dummy member **padding%** is added at the very end; this allows the structure to be moved up in memory by 4 bytes, if necessary, without corrupting subsequent memory contents; //it is vitally important that this member is never written//! The second line adjusts the address of the structure so that it is a multiple of eight.\\ \\ If you want to align the structure at a multiple-of-16 address the padding needs to be 12 bytes in size, most easily arranged by making it an array:\\ | ||
<code bb4w> | <code bb4w> | ||
DIM mystruct{member1, member2, etc, padding%(2)} | DIM mystruct{member1, member2, etc, padding%(2)} | ||
- | !(^mystruct{}+4) = (mystruct{}+12) AND -16 | + | PTR(mystruct{}) = PTR(mystruct{}) AND -16 |
</code> | </code> | ||
\\ | \\ | ||
Line 19: | Line 19: | ||
DIM mystruct{member1, member2, etc} | DIM mystruct{member1, member2, etc} | ||
DIM newdata% DIM(mystruct{})+6 | DIM newdata% DIM(mystruct{})+6 | ||
- | !(^mystruct{}+4) = (newdata%+7) AND -8 | + | PTR(mystruct{}) = (newdata%+7) AND -8 |
</code> | </code> | ||
Similarly to align it on a multiple-of-16 address:\\ | Similarly to align it on a multiple-of-16 address:\\ | ||
Line 25: | Line 25: | ||
DIM mystruct{member1, member2, etc} | DIM mystruct{member1, member2, etc} | ||
DIM newdata% DIM(mystruct{})+14 | DIM newdata% DIM(mystruct{})+14 | ||
- | !(^mystruct{}+4) = (newdata%+15) AND -16 | + | PTR(mystruct{}) = (newdata%+15) AND -16 |
</code> | </code> | ||
Note that you must declare the structure using this method **only once** and not repeat the above code (for example in a loop).\\ \\ If declaring a structure for local use in a procedure or function, use **DIM LOCAL**:\\ | Note that you must declare the structure using this method **only once** and not repeat the above code (for example in a loop).\\ \\ If declaring a structure for local use in a procedure or function, use **DIM LOCAL**:\\ | ||
Line 32: | Line 32: | ||
DIM mystruct{member1, member2, etc} | DIM mystruct{member1, member2, etc} | ||
DIM newdata% LOCAL DIM(mystruct{})+6 | DIM newdata% LOCAL DIM(mystruct{})+6 | ||
- | !(^mystruct{}+4) = (newdata%+7) AND -8 | + | PTR(mystruct{}) = (newdata%+7) AND -8 |
</code> | </code> |