在程序集 x86 中对齐 [英] Align in assembly x86
问题描述
我无法理解align
.
我尝试运行以下命令:
I'm having trouble understanding align
.
I tried running the following:
section .data
align 4
xs: dw 0xA1A2
ys: db 0xB1, 0xB2, 0xB3, 0xB4
看看每个字节是什么,我希望它是内存中的一个连续块,如下所示:
and see what each byte would be, I expected it to be a contiguous block in memory as follows:
for instance: 4 5 6 7 8 9 A B
(addr divisible by 4):[0xA2, 0xA1, 0x0, 0x0, 0xB1, 0xB2, 0xB3, 0xB4]
为了使ys的地址能被4整除相反,它更像是:
In order to make the address of ys divisible by 4 Instead it was more like:
4 5 6 7 8 9
(addr divisible by 4):[0xA2, 0xA1, 0xB1, 0xB2, 0xB3, 0xB4]
显然我对 align 的工作方式有误解.有没有人可以澄清一下?
Obviously I have a misconception of how align works. Could anyone please clear that up?
推荐答案
为了得到你想要的东西,你需要在 ys
数据前直接放置一个 align
指令.此外,要让它使用零字节作为对齐数据,您必须明确指定这一点.(默认为 90h nop
.)像这样:
To get what you want you need to put an align
directive directly in front of the ys
data. Also, to get it to use zero bytes as alignment data you have to explicitly specify this. (The default is 90h nop
.) Like this:
section .data
align 4, db 0
xs: dw 0xA1A2
align 4, db 0
ys: db 0xB1, 0xB2, 0xB3, 0xB4
这是因为该指令不的意思是向前看,将所有数据与此边界对齐".它的意思是,在这个特定点,将发出的数据与这个边界对齐一次".
This is because the directive does not mean "going forward, align all data to this boundary". What it does mean is, "at this particular point align the emitted data once to this boundary".
这篇关于在程序集 x86 中对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!