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

后端 未结 1 501
耶瑟儿~
耶瑟儿~ 2020-12-12 01:18

This is a weird issue that I can\'t seem to find an answer to. This:

#include 
using namespace std;

void show_number(int number) {
    cout          


        
相关标签:
1条回答
  • 2020-12-12 01:55

    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...

    0 讨论(0)
提交回复
热议问题