什么时候应该明确定位指令在汇编使用? [英] When should explicit alignment directives be used in assembly?

查看:150
本文介绍了什么时候应该明确定位指令在汇编使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了一些时间在汇编编程(气体,尤其是),最近我了解了ALIGN指令。我想我已经理解了非常基本的,但我想获得它的本质有更深的了解以及何时使用对齐方式。

I'm spending some time on assembly programming (Gas, in particular) and recently I learned about the align directive. I think I've understood the very basics, but I would like to gain a deeper understanding of its nature and when to use alignment.

例如,我想知道一个简单的C ++ switch语句的组装code。我知道,在某些情况下switch语句是基于跳表,如在code以下几行:

For instance, I wondered about the assembly code of a simple C++ switch statement. I know that under certain circumstances switch statements are based on jump tables, as in the following few lines of code:

    .section    .rodata
    .align 4
    .align 4
.L8:
    .long   .L2
    .long   .L3
    .long   .L4
    .long   .L5
    ...

.align伪4对准下一个4字节边界从而确保获取这些存储单元是有效的,就在下面的数据?我认为这样做是因为可能有事情不对造成的开关语句之前发生的事情。但是为什么这里居然两次调用.align伪?是否有拇指任何规则何时调用.align伪还是应该只是做每当新的数据块存储在存储器和在此之前的东西可能造成未对准

.align 4 aligns the following data on the next 4-byte boundary which ensures that fetching these memory locations is efficient, right? I think this is done because there might be things happening before the switch statement which caused misalignment. But why are there actually two calls to .align? Are there any rules of thumb when to call .align or should it simply be done whenever a new block of data is stored in memory and something prior to this could have caused misalignment?

在的情况下数组,似乎对准在32字节边界上完成只要阵列占据至少32字节。它是更有效地做这种方式还是有其他原因32字节边界?

In case of arrays, it seems that alignment is done on 32-byte boundaries as soon as the array occupies at least 32 byte. Is it more efficient to do it this way or is there another reason for the 32-byte boundary?

我倒是AP preciate任何解释或暗示的文学作品。

I'd appreciate any explanation or hint on literature.

推荐答案

有多个 .align伪指令只是因为编译器内部的工作方式;一会已经足够,并发射只有一个需要额外的工作。

There are more than one .align directives just because of the way the compiler works internally; one would have been sufficient and emitting only one takes extra work.

据对准一般情况下,这是一个复杂的话题,但这里的一篇文章,对英特尔的x64,讨论一些你感兴趣的问题:

As far as alignment in general, it's a complex topic but here's an article for Intel x64 that discusses some of the issues you are interested in:

  • <一个href="http://software.intel.com/en-us/articles/data-alignment-when-migrating-to-64-bit-intel-architecture/">Data对齐迁移到64位英特尔®架构
  • 在当前
  • Data Alignment when Migrating to 64-Bit Intel® Architecture

其他建筑却可能有天壤之别。

Other architecture can be vastly different.

这篇关于什么时候应该明确定位指令在汇编使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆