栈64装配对齐 [英] Stack alignment in x64 assembly
问题描述
是怎样的价值 28小时
(十进制40)是从 RSP
减去计算了以下内容:
how is the value of 28h
(decimal 40) that is subtracted from rsp
calculated in the following:
option casemap:none
includelib kernel32.lib
includelib user32.lib
externdef MessageBoxA : near
externdef ExitProcess : near
.data
text db 'Hello world!', 0
caption db 'Hello x86-64', 0
.code
main proc
sub rsp, 28h ; space for 4 arguments + 16byte aligned stack
xor r9d, r9d ; 4. argument: r9d = uType = 0
lea r8, [caption] ; 3. argument: r8 = caption
lea rdx, [text] ; 2. argument: edx = window text
xor rcx, rcx ; 1. argument: rcx = hWnd = NULL
call MessageBoxA
xor ecx, ecx ; ecx = exit code
call ExitProcess
main endp
end
来自: http://www.japheth.de/JWasm/Win64_1.html
这是我的理解,我将不得不只减去 20小时
,因为我使用的每一个值需要8个字节到4 20小时
。那么,为什么 28小时
被减去,请问是怎么导致16字节对齐?
By my understanding I would have to only subtract 20h
since each value I'm using takes 8 bytes into 4 is 20h
. so why is 28h
being subtracted and how does that result in 16 byte alignment?
推荐答案
我相信这是因为在此之前主
被调用时,堆栈对齐。那么呼叫
之后,呼叫
的行为是推一个8字节的指针(呼叫者的地址)入堆栈。所以在主要开头
,这是8个字节。16字节对齐的。因此,而不是 20小时
需要 28小时
,实际总数达到 28H + 8H
(从呼叫
)或 30小时
。对准。 :)
I believe it's because before main
is called, the stack is aligned. Then after the call
, the act of the call
was to push an 8-byte pointer (address of the caller) onto the stack. So at the beginning of main
, it's 8 bytes off of the 16-byte alignment. Therefore, instead of 20h
you need 28h
, bringing the actual total to 28h + 8h
(from the call
) or 30h
. Alignment. :)
这篇关于栈64装配对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!