gpt4 book ai didi

assembly - x64 程序集中的堆栈对齐

转载 作者:行者123 更新时间:2023-12-02 19:37:19 24 4
gpt4 key购买 nike

rsp中减去28h(十进制40)的值是如何计算的:

    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

根据我的理解,我只需减去 20h,因为我使用的每个值将 8 个字节分成 4 个 20h。那么为什么要减去 28h 以及这如何导致 16 字节对齐?

另请参阅Is reserving stack space necessary for functions less than four arguments?

最佳答案

我相信这是因为在调用 main 之前,堆栈已对齐。然后在call之后,call的行为是推送一个8字节指针(调用者中要返回的地址,即调用之后的地址)指令)入栈。因此,在 main 的开头,它比 16 字节对齐少了 8 个字节。因此,您需要 28h 而不是 20h,从而使实际总数达到 28h + 8h(来自调用)或30h。结盟。 :)

关于assembly - x64 程序集中的堆栈对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19128291/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com