Author Topic: Structure alignment  (Read 3873 times)

sinsi

  • Guest
Structure alignment
« on: December 31, 2017, 10:30:59 AM »
Within a structure, items should be naturally aligned
Code: [Select]
structure1 struct
  v32_1    dd ? ;offset 0
           dd ? ;offset 4, padding
  v64_1    dq ? ;offset 8
structure1 ends

Automatically aligned?
Code: [Select]
structure1 struct 8
  v32_1    dd ? ;offset 0
  v64_1    dq ? ;offset 8
structure1 ends

Should a structure pad the end to align 8?
Code: [Select]
structure2 struct 8
  v64_1    dq ? ;offset 0
  v32_1    dd ? ;offset 8
           dd ?
structure2 ends

Does alignment only matter within a structure?
Code: [Select]
var1  dd ?          ;.data? offset 0
str2  structure2 <> ;.data? offset 4 - str2.v64_1 not aligned to 8 - doesn't matter?

nidud

  • Member
  • *****
  • Posts: 2388
    • https://github.com/nidud/asmc
Re: Structure alignment
« Reply #1 on: December 31, 2017, 11:21:05 AM »
deleted
« Last Edit: February 26, 2022, 02:08:00 AM by nidud »

sinsi

  • Guest
Re: Structure alignment
« Reply #2 on: December 31, 2017, 01:40:05 PM »
So memory alignment isn't required but would be more efficient.
Does the -Zp[n] switch override the structure definition?

Would a nested structure need alignment within the main structure?


Thanks for your time.

jj2007

  • Member
  • *****
  • Posts: 13287
  • Assembly is fun ;-)
    • MasmBasic
Re: Structure alignment
« Reply #3 on: December 31, 2017, 07:19:12 PM »
I agree with Nidud that the Zp switch is the way to go. -Zp8 for 64-bit code, to be precise. Everything else is a can of worms.
Masm32 Tips, Tricks and Traps

Some members can't live without insulting others. It tells us a lot about them.