Fixed regdis.c generation.
[nasm.git] / misc / myC32.mac
blob2088e8597747f5c93c7ee9564a260e1bfbf435a9
1 ; NASM macro set to make interfacing to 32-bit programs easier
2 ; Also cool little macros to make NASM emulate some MASM things.
4 ; Originally included in NASM.  Modifications by Peter Johnson, 1999.
6 ; $Id$
8 %imacro proc 1                  ; begin a procedure definition
9 %push proc
10           global %1
11 %1:       push  ebp
12           mov   ebp, esp
13 %assign %$arg 8
14 ;%assign %$argnum 0
15 %define %$procname %1
16 %endmacro
18 %imacro arg 0-1 4               ; used with the argument name as a label
19 %00       equ %$arg
20 ;%assign %$argnum %$argnum+1
21 ;.arg%$argnum   equ     %1
22 %assign %$arg %1+%$arg
23 %endmacro
25 %imacro endproc 0
26 %ifnctx proc
27 %error Mismatched `endproc'/`proc'
28 %else
29 ;        mov     esp, ebp
30 ;        pop     ebp
31 %ifdef LEGACY_ENDPROC
32         ret
33 %endif
34 ;__end_%$procname:               ; useful for calculating function size
35 ;          global %{$procname}_arglen
36 ;%{$procname}_arglen    equ     %$arg-8
37 ;%assign %$i 1
38 ;%rep %$argnum
39 ;          global %{$procname}_arg%$i
40 ;%{$procname}_arg%$i    equ     %{$procname}.arg%$i
41 ;%assign %$i %$i+1
42 ;%endrep
43 %pop
44 %endif
45 %endmacro
47 ; redefine ret instructions for in-proc cases
48 %imacro ret 0-1
49 %ifnctx proc
50         ret     %1
51 %else
52         mov     esp, ebp
53         pop     ebp
54         ret     %1
55 %endif
56 %endmacro
58 %imacro retf 0-1
59 %ifnctx proc
60         retf    %1
61 %else
62         mov     esp, ebp
63         pop     ebp
64         retf    %1
65 %endif
66 %endmacro
68 %imacro retn 0-1
69 %ifnctx proc
70         retn    %1
71 %else
72         mov     esp, ebp
73         pop     ebp
74         retn    %1
75 %endif
76 %endmacro
78 ; invoke calls a C function
79 ; defaults to word (16 bit) size parameters
80 %macro invoke 1-*
81 %rotate -1
82 ;%define invoketype word
83 %rep (%0-1)
84 ;       %ifidni %1,dword
85 ;               %define invoketype dword
86 ;       %elifidni %1,word
87 ;               %define invoketype word
88 ;       %elifidni %1,byte
89 ;               %define invoketype byte
90 ;       %else
91         %ifidni %1, cs
92                 o16 push %1
93         %elifidni %1, ds
94                 o16 push %1
95         %elifidni %1, es
96                 o16 push %1
97         %elifidni %1, fs
98                 o16 push %1
99         %elifidni %1, gs
100                 o16 push %1
101         %elifidni %1, word cs
102                 o16 push %1
103         %elifidni %1, word ds
104                 o16 push %1
105         %elifidni %1, word es
106                 o16 push %1
107         %elifidni %1, word fs
108                 o16 push %1
109         %elifidni %1, word gs
110                 o16 push %1
111         %else
112                 push %1
113         %endif
114 ;       %endif
115         %rotate -1
116 %endrep
117 call %1
118 %if (%0!=1)
119         add esp, byte %{1}_arglen
120 %endif
121 %endmacro