NASM - The Netwide Assembler
NASM Forum => Programming with NASM => Topic started by: logarithm on December 18, 2012, 08:47:36 PM
-
Hello,
I've ported some code that works great in Linux and Windows with nasm. My issue is with OSX macho-32 and getting around the 16-byte alignment issue. Does anyone have a solution for making sure ESP is always probably aligned without manually editing their code? Better yet is there a macro that can align esp properly for OSX?
Thank you!
-loga
-
Here's a macro to overload the call function with what Mac OS X expects for the CDECL calling convention:
%imacro call 1-*
mov ebx,esp
and esp,0xFFFFFFF0
%if %0 > 1
%if ((%0-1) % 4) > 0
sub esp,16-(((%0-1) % 4) * 4)
%endif
%rep (%0 - 1)
%rotate -1
push %1
%endrep
%rotate -1
%endif
call %1
mov esp,ebx
%endmacro
The above is "shooting from the hip" so to speak, so check it over for logic/syntax errors.
-
%push %1
I don't think we want that first '%', do we?
Best,
Frank
-
%push %1
I don't think we want that first '%', do we?
No. Good catch. That definitely should be push %1.