nasm/misc/c16.mac

83 lines
872 B
Plaintext
Raw Normal View History

2002-05-01 04:52:49 +08:00
; NASM macro set to make interfacing to 16-bit programs easier -*- nasm -*-
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
%imacro proc 1 ; begin a procedure definition
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
%push proc
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
global %1
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
%1: push bp
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
mov bp,sp
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
%ifdef FARCODE PASCAL ; arguments may start at bp+4 or bp+6
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
%assign %$arg 6
2002-05-01 05:08:11 +08:00
%define %$firstarg 6
2002-05-01 04:52:49 +08:00
%else
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
%assign %$arg 4
2002-05-01 05:08:11 +08:00
%define %$firstarg 4
2002-05-01 04:52:49 +08:00
%endif
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
%define %$procname %1
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
%endmacro
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
%imacro arg 0-1 2 ; used with the argument name as a label
2002-05-01 05:08:11 +08:00
%00 equ %$arg
; we could possibly be adding some
; debug information at this point...?
2002-05-01 04:52:49 +08:00
%assign %$arg %1+%$arg
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
%endmacro
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
%imacro endproc 0
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
%ifnctx proc
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
%error Mismatched `endproc'/`proc'
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
%else
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
mov sp,bp
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
pop bp
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
%ifdef PASCAL
2002-05-01 05:08:11 +08:00
retf %$arg - %$firstarg
2002-05-01 04:52:49 +08:00
%elifdef FARCODE
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
retf
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
%else
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
retn
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
%endif
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
__end_%$procname: ; useful for calculating function size
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
%pop
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
%endif
2002-05-01 05:08:11 +08:00
2002-05-01 04:52:49 +08:00
%endmacro
2002-05-01 05:08:11 +08:00