Call C/C++ function from assembly (OSX Mavericks x64)

老子叫甜甜 提交于 2019-11-28 14:13:55
Macmade

The Mac OS X ABI requires a 16-bytes stack alignment, before calling a function.

If your code is working, you're simply lucky, and this explains why you're getting e segmentation fault when modifying previous sections of the code.

So you need to ensure the stack is aligned on a 16-byte boundary.
I already answered a similar question a few times ago:

How to print argv[0] in NASM?

The interesting part is:

; Align stack on a 16 bytes boundary
mov     ebp,                esp
and     esp,                0xFFFFFFF0

Be sure to read the full answer, though...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!