Chinaunix首页 | 论坛 | 博客
  • 博客访问: 496858
  • 博文数量: 174
  • 博客积分: 2502
  • 博客等级: 少校
  • 技术积分: 1923
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-28 09:47
文章分类

全部博文(174)

文章存档

2011年(8)

2010年(16)

2009年(68)

2008年(82)

我的朋友

分类: C/C++

2009-03-21 11:36:21

数据对齐随处理器和编译器的不同而不同,处理好数据对齐可以提高程序的时空效率(节省空间,提高效率),特别是在汇编程序中。很多编译器会利用数据对齐对程序进行优化

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字节数据对齐
阅读(629) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~