问题描述
我很困惑。我正在查看this页面,以了解如何使用堆栈将参数传递给函数。但是,我的代码无法正常工作。鉴于我将计算结果放入rax中,我期望退出代码为9,但实际情况并非如此。取而代之的是,我的退出代码是150。了解x86中的堆栈的调用约定的人是否知道我做错了什么以及如何实现我要解决的问题?我在这样的Mac上使用GAS组装:window.addEventListener("unhandledrejection",event => {
console.warn(`unhandledRejection: ${event.reason.message}`);
});
async function main() {
const p1 = Promise.reject(new Error("Rejected!"));
p1.catch(console.debug); // observe but ignore the error here
try {
await new Promise(r => setTimeout(r,0));
}
finally {
await p1; // throw the error here
}
}
main().catch(e => console.warn(`caught on main: ${e.message}`));
gcc -masm=intel stack_frames.asm
解决方法
您使用的是x86-64,它是64位,而不是32位x86。之所以知道这一点,是因为您能够使用rax
之类的64位寄存器。因此,push
和call
会推送8个字节,而不是4个字节,因此您的参数将位于[rbp + 24]
和[rbp + 16]
,而不是[rbp + 12]
和{{1} }。