سؤال

Since starting to learn at&t assembly about a month ago I was taught that the %ebp register starting at %ebp-4 and going down (ex. -8/-12) were the local variables. Now that I am getting deeper into assembly though I am noticing calls to %ebp-10 and other non multiples of 4. I am wondering how this works and what the significance of this is.

0x08048e2b <+6>:    lea    -0x10(%ebp),%eax

0x08048e2b <+6>:    lea    -0x10(%ebp),%eax

Above are two examples from disassembling a program I am working on now using gdb. How is this data used correctly if, as I am deducing, it is only half way through the variable or supposed data. Wouldn't %ebp-8 or %ebp-12 be the correct version instead of %ebp-10?

I feel like there is probably an intuitive answer to this question, but I'm just not seeing it and haven't been able to find any resources online about it.

هل كانت مفيدة؟

المحلول

0x10 is a multiple of four. It's a hexadecimal number equal to 16 in decimal which, last I looked into the matter, was equal to 4x4. I'm old but I'm pretty sure maths hasn't changed that much since I went to school :-)

In any case, things on the stack aren't required to be aligned on a four-byte boundary. Alignment may speed up certain operations, but:

  • it isn't a mandatory thing on the x86 platforms (on some platforms, accessing misaligned data causes a fault to be raised); and
  • alignment tends to match the argument size (such as a two-byte value "needing" two-byte alignment).
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top