diff options
author | H. Peter Anvin <hpa@zytor.com> | 2002-04-30 21:08:11 +0000 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2002-04-30 21:08:11 +0000 |
commit | 9a633fa3b9b5c772daf4cbca89093bfcd387359b (patch) | |
tree | 8a23f6ff08ea83707a6071d490a3ba47df54a214 /misc/myC32.mac | |
parent | 9f39464e5b32df05159a367cd07b37cf999dae69 (diff) | |
download | nasm-9a633fa3b9b5c772daf4cbca89093bfcd387359b.tar.gz nasm-9a633fa3b9b5c772daf4cbca89093bfcd387359b.tar.bz2 nasm-9a633fa3b9b5c772daf4cbca89093bfcd387359b.zip |
NASM 0.98.25alt
Diffstat (limited to 'misc/myC32.mac')
-rw-r--r-- | misc/myC32.mac | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/misc/myC32.mac b/misc/myC32.mac new file mode 100644 index 0000000..2088e85 --- /dev/null +++ b/misc/myC32.mac @@ -0,0 +1,122 @@ +; NASM macro set to make interfacing to 32-bit programs easier +; Also cool little macros to make NASM emulate some MASM things. +; +; Originally included in NASM. Modifications by Peter Johnson, 1999. +; +; $Id$ + +%imacro proc 1 ; begin a procedure definition +%push proc + global %1 +%1: push ebp + mov ebp, esp +%assign %$arg 8 +;%assign %$argnum 0 +%define %$procname %1 +%endmacro + +%imacro arg 0-1 4 ; used with the argument name as a label +%00 equ %$arg +;%assign %$argnum %$argnum+1 +;.arg%$argnum equ %1 +%assign %$arg %1+%$arg +%endmacro + +%imacro endproc 0 +%ifnctx proc +%error Mismatched `endproc'/`proc' +%else +; mov esp, ebp +; pop ebp +%ifdef LEGACY_ENDPROC + ret +%endif +;__end_%$procname: ; useful for calculating function size +; global %{$procname}_arglen +;%{$procname}_arglen equ %$arg-8 +;%assign %$i 1 +;%rep %$argnum +; global %{$procname}_arg%$i +;%{$procname}_arg%$i equ %{$procname}.arg%$i +;%assign %$i %$i+1 +;%endrep +%pop +%endif +%endmacro + +; redefine ret instructions for in-proc cases +%imacro ret 0-1 +%ifnctx proc + ret %1 +%else + mov esp, ebp + pop ebp + ret %1 +%endif +%endmacro + +%imacro retf 0-1 +%ifnctx proc + retf %1 +%else + mov esp, ebp + pop ebp + retf %1 +%endif +%endmacro + +%imacro retn 0-1 +%ifnctx proc + retn %1 +%else + mov esp, ebp + pop ebp + retn %1 +%endif +%endmacro + +; invoke calls a C function +; defaults to word (16 bit) size parameters +%macro invoke 1-* +%rotate -1 +;%define invoketype word +%rep (%0-1) +; %ifidni %1,dword +; %define invoketype dword +; %elifidni %1,word +; %define invoketype word +; %elifidni %1,byte +; %define invoketype byte +; %else + %ifidni %1, cs + o16 push %1 + %elifidni %1, ds + o16 push %1 + %elifidni %1, es + o16 push %1 + %elifidni %1, fs + o16 push %1 + %elifidni %1, gs + o16 push %1 + %elifidni %1, word cs + o16 push %1 + %elifidni %1, word ds + o16 push %1 + %elifidni %1, word es + o16 push %1 + %elifidni %1, word fs + o16 push %1 + %elifidni %1, word gs + o16 push %1 + %else + push %1 + %endif +; %endif + %rotate -1 +%endrep +call %1 +%if (%0!=1) + add esp, byte %{1}_arglen +%endif +%endmacro + |