数据对齐随处理器和编译器的不同而不同,处理好数据对齐可以提高程序的时空效率(节省空间,提高效率),特别是在汇编程序中。很多编译器会利用数据对齐对程序进行优化
INTEL 80386 PROGRAMMER'S REFERENCE MANUAL 中对数据对齐的解释
Note that words need not be aligned at even-numbered addresses and doublewords need not be aligned at addresses evenly divisible by four. This allows maximum flexibility in data structures (e.g., records containing mixed byte, word, and doubleword items) and efficiency in memory utilization. When used in a configuration with a 32-bit bus, actual transfers of data between processor and memory take place in units of doublewords beginning at addresses evenly divisible by four; however, the processor converts requests for misaligned words or doublewords into the appropriate sequences of requests acceptable to the memory interface. Such misaligned data transfers reduce performance by requiring extra memory cycles. For maximum performance, data structures (including stacks) should be designed in such a way that, whenever possible, word operands are aligned at even addresses and doubleword operands are aligned at addresses evenly divisible by four.
AT&T汇编中用.align 来指定对齐格式,比如objdump -d a.out 常会看到如下
.align 8
表示是8字节数据对齐
阅读(620) | 评论(0) | 转发(0) |