⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scitech.mac

📁 一个免费的汇编语言编译器的源代码
💻 MAC
📖 第 1 页 / 共 2 页
字号:
%imacro   END_IMPORTS_DEF 0
END_STUBS_DEF
%endmacro

else	; __NASM_MAJOR__

;============================================================================
; Macro package when compiling with TASM.
;============================================================================

; Turn off underscores for globals if disabled for all externals

ifdef	__NOU__
__NOU_VAR__			= 1
endif

; Define the __WINDOWS__ symbol if we are compiling for any Windows
; environment

ifdef	__WINDOWS16__
__WINDOWS__ 		= 1
endif
ifdef	__WINDOWS32__
__WINDOWS__ 		= 1
__WINDOWS32_386__ 	= 1
endif
ifdef	__WIN386__
__WINDOWS__ 		= 1
__WINDOWS32_386__ 	= 1
endif
ifdef	__VXD__
__WINDOWS__ 		= 1
__WINDOWS32_386__ 	= 1
		MASM
		.386
		NO_SEGMENTS	= 1
		include	vmm.inc			; IGNORE DEPEND
		include vsegment.inc    ; IGNORE DEPEND
		IDEAL
endif

; Macros for accessing 'generic' registers

ifdef   __FLAT__
		_ax			EQU	eax		; EAX is used for accumulator
		_bx			EQU	ebx		; EBX is used for accumulator
		_cx        	EQU ecx     ; ECX is used for looping
		_dx			EQU	edx		; EDX is used for data register
		_si			EQU	esi		; ESI is the source index register
		_di			EQU	edi		; EDI is the destination index register
		_bp			EQU	ebp		; EBP is used for base pointer register
		_sp			EQU	esp		; ESP is used for stack pointer register
		_es			EQU			; ES and DS are the same in 32 bit PM
		typedef UCHAR BYTE		; Size of a character
		typedef USHORT WORD		; Size of a short
		typedef UINT DWORD		; Size of an integer
		typedef ULONG DWORD		; Size of a long
		typedef BOOL DWORD      ; Size of a boolean
		typedef DPTR DWORD		; Size of a data pointer
		typedef FDPTR FWORD		; Size of a far data pointer
		typedef	NDPTR DWORD		; Size of a near data pointer
		typedef CPTR DWORD		; Size of a code pointer
		typedef FCPTR FWORD		; Size of a far code pointer
		typedef NCPTR DWORD		; Size of a near code pointer
		typedef	DUINT DWORD		; Declare a integer variable
		FPTR        EQU NEAR	; Distance for function pointers
		intsize		=	4		; Size of an integer
		flatmodel	=	1		; This is a flat memory model
		P386                    ; Turn on 386 code generation
		MODEL       FLAT        ; Set up for 32 bit simplified FLAT model
else
		_ax			EQU	ax		; AX is used for accumulator
		_bx			EQU	bx		; BX is used for accumulator
		_cx        	EQU cx     	; CX is used for looping
		_dx			EQU	dx		; DX is used for data register
		_si			EQU	si		; SI is the source index register
		_di			EQU	di		; DI is the destination index register
		_bp			EQU	bp		; BP is used for base pointer register
		_sp			EQU	sp		; SP is used for stack pointer register
		_es			EQU es:		; ES is used for segment override
		typedef UCHAR BYTE      ; Size of a character
		typedef USHORT WORD		; Size of a short
		typedef UINT WORD		; Size of an integer
		typedef ULONG DWORD		; Size of a long
		typedef BOOL WORD		; Size of a boolean
		typedef DPTR DWORD		; Size of a data pointer
		typedef FDPTR DWORD		; Size of a far data pointer
		typedef	NDPTR WORD		; Size of a near data pointer
		typedef CPTR DWORD		; Size of a code pointer
		typedef FCPTR DWORD		; Size of a far code pointer
		typedef NCPTR WORD		; Size of a near code pointer
		typedef	DUINT WORD		; Declare a integer variable
		FPTR        EQU FAR		; Distance for function pointers
		intsize		=	2		; Size of an integer
		P386					; Turn on 386 code generation
endif
        invert      EQU not

; Provide a typedef for real floating point numbers

ifdef	DOUBLE
typedef	REAL	QWORD
typedef	DREAL	QWORD
else
typedef	REAL	DWORD
typedef	DREAL	DWORD
endif

; Macros to access the floating point stack registers to convert them
; from NASM style to TASM style

st0			EQU		st(0)
st1			EQU		st(1)
st2			EQU		st(2)
st3			EQU		st(3)
st4			EQU		st(4)
st5			EQU		st(5)
st6			EQU		st(6)
st7			EQU		st(7)
st8			EQU		st(8)

; Boolean truth values (same as those in debug.h)

ifndef	__VXD__
False		=		0
True		=		1
No			=		0
Yes			=		1
Yes			=		1
endif

; Macros for the _DATA data segment. This segment contains initialised data.

MACRO   begdataseg name
ifdef	__VXD__
		MASM
VXD_LOCKED_DATA_SEG
		IDEAL
else
ifdef   flatmodel
		DATASEG
else
SEGMENT _DATA DWORD PUBLIC USE16 'DATA'
endif
endif
ENDM

MACRO   enddataseg name
ifdef	__VXD__
		MASM
VXD_LOCKED_DATA_ENDS
		IDEAL
else
ifndef  flatmodel
ENDS    _DATA
endif
endif
ENDM

; Macro for the main code segment.

MACRO   begcodeseg name
ifdef	__VXD__
		MASM
VXD_LOCKED_CODE_SEG
		IDEAL
else
ifdef   flatmodel
		CODESEG
		ASSUME  CS:FLAT,DS:FLAT,SS:FLAT
else
SEGMENT &name&_TEXT PARA PUBLIC USE16 'CODE'
		ASSUME CS:&name&_TEXT,DS:_DATA
endif
endif
ENDM

; Macro for a near code segment

MACRO   begcodeseg_near
ifdef   flatmodel
		CODESEG
		ASSUME  CS:FLAT,DS:FLAT,SS:FLAT
else
SEGMENT _TEXT PARA PUBLIC USE16 'CODE'
		ASSUME CS:_TEXT,DS:_DATA
endif
ENDM

MACRO   endcodeseg name
ifdef	__VXD__
		MASM
VXD_LOCKED_CODE_ENDS
		IDEAL
else
ifndef  flatmodel
ENDS    &name&_TEXT
endif
endif
ENDM

MACRO   endcodeseg_near
ifndef  flatmodel
ENDS    _TEXT
endif
ENDM

; Macro to be invoked at the start of all modules to set up segments for
; later use.

MACRO   header name
begdataseg name
enddataseg name
ENDM

; Macro for an extern C symbol. If the C compiler requires leading
; underscores, then the underscores are added to the symbol names, otherwise
; they are left off. The symbol name is referenced in the assembler code
; using the non-underscored symbol name.

MACRO   cextern	name,size
ifdef	__NOU_VAR__
		EXTRN	name:size
else
		EXTRN	_&name&:size
name	EQU		_&name&
endif
ENDM

MACRO   cexternfunc	name,size
ifdef	__NOU__
		EXTRN	name:size
else
		EXTRN	_&name&:size
name	EQU		_&name&
endif
ENDM

MACRO   stdexternfunc	name,args,size
ifdef	STDCALL_MANGLE
		EXTRN	_&name&@&num_args&:size
name	EQU		_&name&@&num_args
else
		EXTRN	name:size
endif
ENDM

; Macro for a public C symbol. If the C compiler requires leading
; underscores, then the underscores are added to the symbol names, otherwise
; they are left off. The symbol name is referenced in the assembler code
; using the non-underscored symbol name.

MACRO	cpublic name
ifdef	__NOU_VAR__
name:
		PUBLIC	name
else
_&name&:
		PUBLIC	_&name&
name	EQU		_&name&
endif
ENDM

; Macro for an global C symbol. If the C compiler requires leading
; underscores, then the underscores are added to the symbol names, otherwise
; they are left off. The symbol name is referenced in the assembler code
; using the non-underscored symbol name.

MACRO	cglobal name
ifdef	__NOU_VAR__
		PUBLIC	name
else
		PUBLIC	_&name&
name	EQU		_&name&
endif
ENDM

; Macro for an global C function symbol. If the C compiler requires leading
; underscores, then the underscores are added to the symbol names, otherwise
; they are left off. The symbol name is referenced in the assembler code
; using the non-underscored symbol name.

MACRO	cglobalfunc name
ifdef	__NOU__
		PUBLIC	name
else
		PUBLIC	_&name&
name	EQU		_&name&
endif
ENDM

; Macro to start a C callable function. This will be a far function for
; 16-bit code, and a near function for 32-bit code.

MACRO   cprocstatic name       	; Set up model independant private proc
ifdef flatmodel
PROC   	name NEAR
else
PROC    name FAR
endif
LocalSize	= 0
ENDM

MACRO   cprocstart name        	; Set up model independant proc
ifdef flatmodel
ifdef	__NOU__
PROC   	name NEAR
else
PROC   	_&name& NEAR
endif
else
ifdef	__NOU__
PROC    name FAR
else
PROC    _&name& FAR
endif
endif
LocalSize	= 0
		cglobalfunc	name
ENDM

MACRO   cprocnear name         	; Set up near proc
ifdef	__NOU__
PROC    name NEAR
else
PROC    _&name& NEAR
endif
LocalSize	= 0
		cglobalfunc	name
ENDM

MACRO   cprocfar name           ; Set up far proc
ifdef	__NOU__
PROC    name FAR
else
PROC    _&name& FAR
endif
LocalSize	= 0
		cglobalfunc	name
ENDM

MACRO   cprocend	           ; End procedure macro
ENDP
ENDM

; This macro sets up a procedure to be exported from a 16 bit DLL. Since the
; calling conventions are always _far _pascal for 16 bit DLL's, we actually
; rename this routine with an extra underscore with 'C' calling conventions
; and a small DLL stub will be provided by the high level code to call the
; assembler routine.

MACRO   cprocstartdll16 name
ifdef	__WINDOWS16__
cprocstart	_&name&
else
cprocstart	name
endif
ENDM

; Macros for entering and exiting C callable functions. Note that we must
; always save and restore the SI and DI registers for C functions, and for
; 32 bit C functions we also need to save and restore EBX and clear the
; direction flag.

MACRO	save_c_regs
ifdef	flatmodel
		push	ebx
endif
		push	_si
		push	_di
ENDM

MACRO	enter_c
		push    _bp
		mov     _bp,_sp
	IFDIFI	<LocalSize>,<0>
		sub		_sp,LocalSize
	ENDIF
		save_c_regs
ENDM

MACRO	restore_c_regs
		pop		_di
		pop		_si
ifdef	flatmodel
		pop		ebx
endif
ENDM

MACRO	leave_c
		restore_c_regs
		cld
	IFDIFI	<LocalSize>,<0>
		mov     _sp,_bp
	ENDIF
		pop     _bp
ENDM

MACRO   use_ebx
ifdef flatmodel
		push    ebx
endif
ENDM

MACRO   unuse_ebx
ifdef flatmodel
		pop     ebx
endif
ENDM

; Macros for saving and restoring the value of DS,ES,FS,GS when it is to
; be used in assembly routines. This evaluates to nothing in the flat memory
; model, but is saves and restores DS in the large memory model.

MACRO	use_ds
ifndef flatmodel
		push	ds
endif
ENDM

MACRO	unuse_ds
ifndef flatmodel
		pop		ds
endif
ENDM

MACRO	use_es
ifndef flatmodel
		push	es
endif
ENDM

MACRO	unuse_es
ifndef flatmodel
		pop		es
endif
ENDM

; Macros for loading the address of a data pointer into a segment and
; index register pair. The macro explicitly loads DS or ES in the 16 bit
; memory model, or it simply loads the offset into the register in the flat
; memory model since DS and ES always point to all addressable memory. You
; must use the correct _REG (ie: _BX) macros for documentation purposes.

MACRO	_lds	reg, addr
ifdef flatmodel
		mov     reg,addr
else
		lds		reg,addr
endif
ENDM

MACRO   _les	reg, addr
ifdef flatmodel
		mov     reg,addr
else
		les		reg,addr
endif
ENDM

; Macros for adding and subtracting a value from registers. Two value are
; provided, one for 16 bit modes and another for 32 bit modes (the extended
; register is used in 32 bit modes).

MACRO   _add	reg, val16, val32
ifdef flatmodel
		add		e&reg&, val32
else
		add		reg, val16
endif
ENDM

MACRO	_sub	reg, val16, val32
ifdef flatmodel
		sub		e&reg&, val32
else
		sub		reg, val16
endif
ENDM

; Macro to clear the high order word for the 32 bit extended registers.
; This is used to convert an unsigned 16 bit value to an unsigned 32 bit
; value, and will evaluate to nothing in 16 bit modes.

MACRO	clrhi	reg
ifdef	flatmodel
		movzx	e&reg&,reg
endif
ENDM

MACRO	sgnhi	reg
ifdef	flatmodel
		movsx	e&reg&,reg
endif
ENDM

; Macro to load an extended register with an integer value in either mode

MACRO	loadint	reg,val
ifdef flatmodel
		mov		e&reg&,val
else
		xor		e&reg&,e&reg&
		mov     reg,val
endif
ENDM

; Macros to load and store integer values with string instructions

MACRO	LODSINT
ifdef flatmodel
		lodsd
else
		lodsw
endif
ENDM

MACRO	STOSINT
ifdef flatmodel
		stosd
else
		stosw
endif
ENDM

; Macros to provide resb, resw, resd compatibility with NASM

MACRO	dclb	count
db	count dup (0)
ENDM

MACRO	dclw	count
dw	count dup (0)
ENDM

MACRO	dcld	count
dd	count dup (0)
ENDM

; Macros to provide resb, resw, resd compatibility with NASM

MACRO	resb	count
db	count dup (?)
ENDM

MACRO	resw	count
dw	count dup (?)
ENDM

MACRO	resd	count
dd	count dup (?)
ENDM

; Macros to declare assembler stubs for function structures

MACRO	BEGIN_STUBS_DEF	name, firstOffset
begdataseg  _STUBS
ifdef	__NOU_VAR__
		EXTRN	name:DWORD
STUBS_START	=   name
else
		EXTRN	_&name&:DWORD
name	EQU		_&name&
STUBS_START	=   _&name
endif
enddataseg  _STUBS
begcodeseg  _STUBS
off = firstOffset
ENDM

MACRO   DECLARE_STUB	name
ifdef	__NOU__
name:
		PUBLIC  name
else
_&name:
		PUBLIC  _&name
endif
		jmp     [DWORD STUBS_START+off]
off = off + 4
ENDM

MACRO   DECLARE_STDCALL	name,num_args
ifdef	STDCALL_MANGLE
_&name&@&num_args&:
		PUBLIC  _&name&@&num_args&
else
name:
		PUBLIC  name
endif
		jmp     [DWORD STUBS_START+off]
off = off + 4
ENDM

MACRO   END_STUBS_DEF
endcodeseg  _STUBS
ENDM

MACRO	BEGIN_IMPORTS_DEF	name
BEGIN_STUBS_DEF	name,4
ENDM

MACRO   DECLARE_IMP	name
DECLARE_STUB	name
ENDM

MACRO   END_IMPORTS_DEF
END_STUBS_DEF
ENDM

endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -