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

📄 cwl.asm

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 ASM
📖 第 1 页 / 共 5 页
字号:
	pop	esi
;
;Skip any remaining white space.
;
@@0:	inc	edi
	cmp	b[edi-1]," "
	jz	@@0
	cmp	b[edi-1],9
	jz	@@0
	dec	edi
;
;Scan the length of the symbol.
;
	xor	ecx,ecx
	mov	ebx,edi
@@1:	cmp	b[edi],0
	jz	@@2
	cmp	b[edi]," "
	jz	@@2
	cmp	b[edi],9
	jz	@@2
	inc	ecx
	inc	edi
	jmp	@@1
;
;Get some memory for this text.
;
@@2:	inc	ecx
	call	Malloc
	mov	ErrorNumber,2
	jc	@@9
;
;Copy text through to allocated memory.
;
	push	esi
	mov	edi,esi
	mov	esi,ebx
	dec	ecx
	mov	b[edi],cl
	inc	edi
	rep	movsb
	pop	esi
;
;Set modules name string.
;
	mov	ModuleName,esi
;
@@8:	clc
	jmp	@@10
;
@@9:	stc
;
@@10:	ret
DEF_NameCOM	endp


;*******************************************************************************
;
;Process a DEF file EXPORT command.
;
;On Entry:
;
;EDI	- rest of command statement.
;
DEF_ExportCOM	proc	near
	push	esi
	mov	esi,edi
	call	UpperString
	pop	esi
;
;Skip any remaining white space.
;
@@0:	inc	edi
	cmp	b[edi-1]," "
	jz	@@0
	cmp	b[edi-1],9
	jz	@@0
	dec	edi
;
;Scan the length of the symbol.
;
	xor	ecx,ecx
	mov	ebx,edi
@@1:	cmp	b[edi],0
	jz	@@2
	cmp	b[edi]," "
	jz	@@2
	cmp	b[edi],9
	jz	@@2
	inc	ecx
	inc	edi
	jmp	@@1
;
;Get some memory for this symbol.
;
@@2:	add	ecx,size EXPORT
	call	Malloc
	mov	ErrorNumber,2
	jc	@@9
;
;Make sure EXPORT is initialised to at least zero's.
;
	pushm	ecx,edi
	xor	eax,eax
	mov	ecx,size EXPORT
	mov	edi,esi
	rep	stosb
	popm	ecx,edi
;
;Store text length.
;
	sub	ecx,size EXPORT
	mov	EXPORT.EXP_TextLen[esi],cl
	mov	edx,esi
	mov	edi,esi
	mov	esi,ebx
	add	edi,size EXPORT
;
;Copy symbol.
;
@@3:	mov	al,[esi]
	mov	[edi],al
	inc	esi
	inc	edi
	dec	ecx
	jnz	@@3
;
;Expand the EXPORT list.
;
	ExpandList EXPORTList,ListBumpG
	mov	ErrorNumber,2
	jc	@@9
;
;Add this entry.
;
	mov	esi,EXPORTList
	mov	ecx,[esi]
	inc	d[esi]	
	mov	d[esi+4+ecx*4],edx
;
@@8:	clc
	jmp	@@10
;
@@9:	stc
;
@@10:	ret
DEF_ExportCOM	endp


;*******************************************************************************
;
;Process a DEF file IMPORT command.
;
;On Entry:
;
;EDI	- rest of command statement.
;
DEF_ImportCOM	proc	near
	mov	IMPORTInternal,0
	push	esi
	mov	esi,edi
	call	UpperString
	pop	esi
;
;Get a new entry for this IMPORT.
;
	mov	ecx,size IMPORT
	call	Malloc
	mov	ErrorNumber,2
	jc	@@9
	ExpandList IMPORTList,ListBumpG
	mov	ErrorNumber,2
	jc	@@9
	mov	ebx,IMPORTList
	mov	eax,[ebx]		;get entry number.
	inc	d[ebx]
	mov	d[ebx+4+eax*4],esi	;store pointer to this entry.
	mov	IMPORTTemp,esi
	push	edi
	mov	edi,esi
	mov	ecx,size IMPORT
	xor	eax,eax
	rep	stosb
	pop	edi
;
;Skip any remaining white space.
;
@@0:	inc	edi
	cmp	b[edi-1]," "
	jz	@@0
	cmp	b[edi-1],9
	jz	@@0
	dec	edi
;
;Scan the length of the module name.
;
	xor	edx,edx
	mov	ebx,edi
@@1:	cmp	b[edi],0
	jz	@@2
	cmp	b[edi]," "
	jz	@@2_0
	cmp	b[edi],9
	jz	@@2_0
	cmp	b[edi],"."
	jz	@@3
	inc	edx
	inc	edi
	jmp	@@1
;
;May be specifying an internal name.
;
@@2_0:	cmp	IMPORTInternal,0
	jnz	@@2		;already got an internal name.
	cmp	b[edi+1],0
	jz	@@2
	mov	IMPORTInternal,ebx
	mov	IMPORTInternal+4,edx
	jmp	@@0
;
;Not the format we were expecting so print a warning and ignore this line.
;
@@2:	mov	ErrorNumber,33
	pushad
	mov	edi,offset ErrorNameSpace1
	mov	ErrorName+4,edi
	mov	eax,DEFLineNumber
	call	Bin2Dec
	call	PrintError
	popad
	jmp	@@8
;
;See if this module name is already in the list.
;
@@3:	inc	edi		;skip the period
	mov	esi,IMPORTModules
	mov	ebp,[esi]
	add	esi,4
@@4:	or	ebp,ebp
	jz	@@11
	pushm	esi,ebx
	mov	esi,[esi]
	cmp	dl,[esi]		;right length?
	jnz	@@7
	mov	ecx,edx
	inc	esi
@@5:	mov	al,[esi]
	mov	ah,[ebx]
	call	UpperChar
	xchg	ah,al
	call	UpperChar
	xchg	ah,al
	cmp	al,ah
	jnz	@@7
	inc	esi
	inc	ebx
	dec	ecx
	jnz	@@5
	popm	esi,ebx
	mov	eax,IMPORTModules
	mov	eax,[eax]
	sub	eax,ebp		;Get entry number.
	jmp	@@12		;found a match.
@@7:	popm	esi,ebx
	add	esi,4
	dec	ebp
	jmp	@@4
;
;Need to add a new entry to the list.
;
@@11:	mov	ecx,edx
	inc	ecx
	;
	mov	eax,ecx
	add	eax,4
	add	IMPORTLength,eax	;add space for this entry.
	add	IMPORTLength+4,eax
	add	IMPORTLength+8,eax
	;
	call	Malloc		;get memory for module name string.
	mov	ErrorNumber,2
	jc	@@9
	dec	ecx
	mov	b[esi],cl
	pushm	esi,edi
	mov	edi,esi
	inc	edi
	mov	esi,ebx
@@modname0:	mov	al,[esi]
	inc	esi
	call	UpperChar
	mov	[edi],al
	inc	edi
	dec	ecx
	jnz	@@modname0
	popm	esi,edi
	;
	ExpandList IMPORTModules,ListBumpG
	mov	ErrorNumber,2
	jc	@@9
	;
	mov	ebx,IMPORTModules
	mov	eax,[ebx]		;get entry number.
	inc	d[ebx]
	mov	d[ebx+4+eax*4],esi	;store pointer to this name.
;
;Update this IMPORT with the module name index.
;
@@12:	mov	esi,IMPORTTemp
	mov	IMPORT.IMP_Module[esi],eax
;
;Now scan the length of the symbol name.
;
	mov	ebx,edi
	xor	edx,edx
@@13:	cmp	b[edi],0
	jz	@@14
	cmp	b[edi]," "
	jz	@@14
	cmp	b[edi],9
	jz	@@14
	inc	edi
	inc	edx
	jmp	@@13
;
;Set "internal" name for this import.
;
@@14:	pushad
	cmp	IMPORTInternal,0
	jz	@@14_0
	mov	ebx,IMPORTInternal
	mov	edx,IMPORTInternal+4
@@14_0:	mov	ecx,edx
	inc	ecx
	call	Malloc
	jc	@@14_1
	mov	edi,esi
	mov	esi,IMPORTTemp
	mov	IMPORT.IMP_IName[esi],edi
	dec	ecx
	mov	[edi],cl
	inc	edi
	mov	esi,ebx
	rep	movsb
	clc
@@14_1:	popad
	jnc	@@14_2
	mov	ErrorNumber,2
	call	PrintError
	jmp	@@8
;
;Check if the symbol is actually an ordinal number.
;
@@14_2:	mov	edi,ebx
	cmp	b[edi],"0"
	jc	@@21
	cmp	b[edi],"9"+1
	jnc	@@21
	;
	;Check an internal name has been set.
	;
	cmp	IMPORTInternal,0
	jnz	@@25
	pushad
	mov	ErrorNumber,34
	mov	edi,offset ErrorNameSpace1
	mov	ErrorName+4,edi
	mov	eax,DEFLineNumber
	call	Bin2Dec
	call	PrintError
	popad
	jmp	@@8
	;
@@25:	;Get the ordinal number.
	;
	mov	ebx,edi
	xor	ecx,ecx
@@22:	cmp	b[edi],0
	jz	@@24
	cmp	b[edi]," "
	jz	@@24
	cmp	b[edi],9
	jz	@@24
	cmp	b[edi],"0"
	jc	@@23
	cmp	b[edi],"9"+1
	jnc	@@23
	mov	eax,ecx
	shl	eax,1
	shl	ecx,3
	add	ecx,eax
	xor	eax,eax
	mov	al,[edi]
	sub	al,"0"
	add	ecx,eax
	inc	edi
	jmp	@@22
	;
@@23:	pushad
	mov	ErrorNumber,35
	mov	edi,offset ErrorNameSpace1
	mov	ErrorName+4,edi
	mov	eax,DEFLineNumber
	call	Bin2Dec
	call	PrintError
	popad
	jmp	@@8
	;
@@24:	or	ecx,ecx
	jz	@@23
	mov	esi,IMPORTTemp
	mov	IMPORT.IMP_Name[esi],ecx	;set name ordinal.
	or	IMPORT.IMP_Flags[esi],128	;flag as ordinal.
	jmp	@@8
;
;Check if this name already exists.
;
@@21:	mov	esi,IMPORTNames
	mov	ebp,[esi]
	add	esi,4
@@15:	or	ebp,ebp
	jz	@@19
	pushm	ebx,esi
	mov	esi,[esi]
	cmp	dl,[esi]		;right length?
	jnz	@@18
	inc	esi
	mov	ecx,edx
@@16:	mov	al,[esi]
	mov	ah,[ebx]
	cmp	CaseSensitive,0
	jnz	@@17
	call	UpperChar
	xchg	ah,al
	call	UpperChar
	xchg	ah,al
@@17:	cmp	al,ah
	jnz	@@18
	inc	esi
	inc	ebx
	or	al,al		;end of the symbol?
	jnz	@@16
	popm	ebx,esi
	mov	eax,IMPORTNames
	mov	eax,[eax]
	sub	eax,ebp		;get entry number.
	jmp	@@20
@@18:	popm	ebx,esi
	add	esi,4
	dec	ebp
	jmp	@@15
;
;Need to add this name to the list.
;
@@19:	mov	ecx,edx
	inc	ecx
	;
	mov	eax,ecx
	add	eax,4
	add	IMPORTLength,eax	;add space for this entry.
	add	IMPORTLength+8,eax
	;
	call	Malloc		;get memory for module name string.
	mov	ErrorNumber,2
	jc	@@9
	dec	ecx
	mov	b[esi],cl
	pushm	esi,edi
	mov	edi,esi
	inc	edi
	mov	esi,ebx
	rep	movsb		;copy symbol name.
	popm	esi,edi
	;
	ExpandList IMPORTNames,ListBumpG
	mov	ErrorNumber,2
	jc	@@9
	;
	mov	ebx,IMPORTNames
	mov	eax,[ebx]		;get entry number.
	inc	d[ebx]
	mov	d[ebx+4+eax*4],esi	;store pointer to this name.
;
;Update this IMPORT with the symbol name index.
;
@@20:	mov	esi,IMPORTTemp
	mov	IMPORT.IMP_Name[esi],eax
;
@@8:	clc
	jmp	@@10
;
@@9:	stc
;
@@10:	ret
DEF_ImportCOM	endp


;*******************************************************************************
;Initialise file buffer.
;
;On Entry:
;
;EBX	- File handle.
;
;On Exit:
;
;ALL registers preserved.
;
;*******************************************************************************
InitFileBuffer	proc	near
	mov	FileBufferCount,0	;reset buffer count.
	mov	FileBufferHandle,ebx	;store handle.
	ret
InitFileBuffer	endp


;*******************************************************************************
;Read a line of text from input file specified.
;
;On Entry:
;
;EDI	- Buffer.
;
;On Exit:
;
;Carry set on error else,
;
;ECX	- Buffer length, -1=EOF.
;
;*******************************************************************************
ReadBufferLine	proc	near
	public ReadBufferLine
	pushm	eax,ebx,edx,edi
	mov	ebx,FileBufferHandle
	xor	ecx,ecx		;reset bytes so far count.
;
;Read a byte loop point.
;
l0:	call	ReadBufferByte
	jc	l9
	mov	[edi],al
	or	eax,eax		;read anything?
	jz	CheckEOF
	cmp	b[edi],13		;EOL?
	jz	CheckLF
	cmp	b[edi],26
	jz	SoftEOF		;move to the end of the file, then do an EOL.
	inc	ecx
	inc	edi
	cmp	ecx,1024		;line getting a bit long?
	jnc	SoftEOF
	jmp	l0		;keep going.
;
;Found a CR so look for the coresponding LF.
;
CheckLF:	mov	b[edi],0		;terminate this line.
	inc	edi
	call	ReadBufferByte
	jc	l9
	mov	b[edi],al
	or	eax,eax		;read anything?
	jz	l9		;no LF here is an error.
	cmp	b[edi],10		;/
	jnz	l9		;/
	jmp	l8
;
;Move to the end of the source file to make it look like we really read everything.
;
SoftEOF:	pushm	ebx,ecx,edi
	mov	ebx,FileBufferHandle
	xor	ecx,ecx
	mov	al,2
	call	SetFilePointer
	popm	ebx,ecx,edi		;fall through to treat like hard EOF.
	mov	FileBufferCount,0
;
;Check if we should return EOF this time or next.
;
CheckEOF:	or	ecx,ecx		;read anything on this line yet?
	jnz	l8		;do EOL this time.
;
;Return EOF this time.
;
EOF:	or	ecx,-1
;
;Terminate the line.
;
l8:	mov	b[edi],0		;terminate the line.
	clc
	jmp	l10
;
;Some sort of error occured so make sure carry is set.
;
l9:	stc
;
l10:	popm	eax,ebx,edx,edi
	ret
ReadBufferLine	endp


;*******************************************************************************
;Read a byte from the file buffer.
;
;On Entry:
;
;None
;
;On Exit:
;
;Carry set on error else,
;
;AH	- Bytes read, ie, AH=0 indicates EOF otherwise AH=1
;AL	- Byte read.
;
;eg, if EAX=0 and no carry then EOF reached.
;
;Don't mix normal ReadFile call's with this call, they don't take account of
;each other.
;
;*******************************************************************************
ReadBufferByte	proc	near
	xor	eax,eax
	cmp	FileBufferCount,0	;anything in the buffer?
	jnz	r0
	;
	;Need to re-fill the buffer.
	;
	pushm	eax,ebx,ecx,edx
	mov	edx,offset FileBuffer
	mov	ebx,FileBufferHandle
	mov	ecx,1024
	call	ReadFile
	mov	FileBufferCount,eax
	mov	FileBufferPosition,offset FileBuffer
	popm	eax,ebx,ecx,edx
	jc	r8
	;
r0:	cmp	FileBufferCount,0	;still zero?
	jz	r8
	push	esi
	mov	esi,FileBufferPosition
	inc	FileBufferPosition
	dec	FileBufferCount
	mov	al,[esi]
	inc	ah
	pop	esi
	clc
	;
r8:	ret
ReadBufferByte	endp


;------------------------------------------------------------------------------
;
;Add some linker supplied PUBDEF's for WLINK compatibility.
;
;On Entry:
;
;nothing.
;
;On Exit:
;
;Carry set on error else,
;
;All registers preserved.
;
AddInternalPUBDEFs proc near
	pushad
;
;Add _end
;
	ExpandList PUBLICList,ListBumpG
	mov	ErrorNumber,2
	jc	@@9
	mov	edi,PUBLICList
	mov	eax,[edi]
	inc	d[edi]		;update number of entries.
	lea	edi,[edi+4+eax*4]	;point to new entry.
	mov	[edi],offset InternalPUBDEF__end
	or	d[PUB.PFlags+InternalPUBDEF__end],2
;
;Add _edata
;
	ExpandList PUBLICList,ListBumpG
	mov	ErrorNumber,2
	jc	@@9
	mov	edi,PUBLICList
	mov	eax,[edi]
	inc	d[edi]		;update number of entries.
	lea	edi,[edi+4+eax*4]	;point to new entry.
	mov	[edi],offset InternalPUBDEF__edata
	or	d[PUB.PFlags+InternalPUBDEF__edata],2
;
;Add _estack
;
	ExpandList PUBLICList,ListBumpG
	mov	ErrorNumber,2
	jc	@@9

⌨️ 快捷键说明

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