NASM 0.98p3.3
[nasm.git] / c16.mac
blob2853db51fad78dc39bbfaa0966185e995338024b
1 ; NASM macro set to make interfacing to 16-bit programs easier -*- nasm -*-\r
2 \r
3 %imacro proc 1                  ; begin a procedure definition\r
4 %push proc\r
5           global %1\r
6 %1:       push bp\r
7           mov bp,sp\r
8 %ifdef FARCODE PASCAL           ; arguments may start at bp+4 or bp+6\r
9 %assign %$arg 6\r
10 %define %$firstarg 6\r
11 %else\r
12 %assign %$arg 4\r
13 %define %$firstarg 4\r
14 %endif\r
15 %define %$procname %1\r
16 %endmacro\r
18 %imacro arg 0-1 2               ; used with the argument name as a label\r
19 %00       equ %$arg\r
20                                 ; we could possibly be adding some\r
21                                 ; debug information at this point...?\r
22 %assign %$arg %1+%$arg\r
23 %endmacro\r
25 %imacro endproc 0\r
26 %ifnctx proc\r
27 %error Mismatched `endproc'/`proc'\r
28 %else\r
29           mov sp,bp\r
30           pop bp\r
31 %ifdef PASCAL\r
32           retf %$arg - %$firstarg\r
33 %elifdef FARCODE\r
34           retf\r
35 %else\r
36           retn\r
37 %endif\r
38 __end_%$procname:               ; useful for calculating function size\r
39 %pop\r
40 %endif\r
41 %endmacro\r