	.text
;********************************
; DoHash: used in ncpp.c
;********************************
	.globl	_DoHash
_DoHash:
	pushl	%esi
	xor	%eax,%eax
	movl	%eax,%edx
	movl	8(%esp),%ecx
	movl	12(%esp),%esi
_$DoHash1:
	lodsb
	add	%eax,%edx
	loop	_$DoHash1
	mov	%edx,%eax
	pop	%esi
	ret
	.align	2
;********************************
; cpplookup: Used in ncpp.c
;********************************
	.globl	_cpplookup
_cpplookup:
	pushl	%ebp
	movl	%esp,%ebp
	pushl	%edi
	pushl	%esi
	pushl	%ebx
	movl	8(%ebp),%eax
	movl	12(%eax),%esi
	movl	%esi,%ebx
	movl	8(%eax),%ecx
	movl	%ecx,%edi
	xor	%eax,%eax
	mov	%eax,%edx
	orl	%ecx,%ecx
	je	_$1700
;	Add all characters of the token:
;	Entry conditions:
;	%esi contains the character string to search
;	%eax is zeroed
;	%edx (result) is zero
_$1701:
	lodsb
	add	%eax,%edx
	decl	%ecx
	jne	_$1701
;	index the nlist variable wth %edx modulo 1024
	andl	$1023,%edx
	movl	_nlist(,%edx,4),%esi
	jmp	_$1705
_$1704:
;	Find matching char string.
;	%esi contains the current token in the list
;	%edi contains its length
;	%ebx is the string to compare with
	cmpl	8(%esi),%edi
	jne	_$1707
	movl	%edi,%ecx
	movl	4(%esi),%edx
_$comparestrings:
	movb	-1(%edx,%ecx),%al
	cmpb	-1(%ebx,%ecx),%al
	jne	_$1707
	decl	%ecx
	jne	_$comparestrings
	jmp	_$1706
_$1707:
	movl	(,%esi),%esi
_$1705:
	or	%esi,%esi
	jne	_$1704
_$1706:
	movl	%esi,%eax
_$1700:
	popl	%ebx
	popl	%esi
	popl	%edi
	popl	%ebp
	ret
	.align	2
;**********************************
; is_dnrange: used in asm.c
;**********************************
	.globl	_is_dnrange
_is_dnrange:
	movl	4(%esp),%ecx
	movl	8(%esp),%edx
	xor	%eax,%eax
	or	%ecx,%ecx
	je	_$exitDn_Range
_$loopDnRange:
	movl	4(%ecx),%ecx
	cmpl	%edx,%ecx
	sete	%al
	je	_$exitDn_Range
	or	%ecx,%ecx
	jne	_$loopDnRange
_$exitDn_Range:
	ret
	.align	2
;***********************************
; sametree: used in win32.c
;***********************************
	.globl _sametree
_sametree:
	pushl	%esi
	pushl	%edi
	movl	12(%esp),%edi
	movl	16(%esp),%esi
_$00sametree:
	xor	%eax,%eax
	or	%edi,%edi
	jne	_$2126
	or	%esi,%esi
	sete	%al
	je	_$2121
_$2126:
	movw	(,%edi),%cx
	cmpw	(,%esi),%cx
	jne	_$2121
	movl	4(%edi),%ecx
	cmpl	4(%esi),%ecx
	jne	_$2121
	pushl	16(%esi)
	pushl	16(%edi)
	call	_sametree
	add	$8,%esp
	or	%eax,%eax
	je	_$2121
	movl	20(%edi),%edi
	movl	20(%esi),%esi
	jmp	_$00sametree
_$2121:
	popl	%edi
	popl	%esi
	ret
	.align	2
;***********************************
; DoRead: called from ncpp.c
;***********************************
	.globl	_DoRead
_DoRead:
	pushl	%ebp
	movl	%esp,%ebp
	subl	$20,%esp
	pushl	%esi
	pushl	%edi
	xor	%eax,%eax
	movl	%eax,-12(%ebp)
	pushl	%eax
	leal	-12(%ebp),%edx
	pushl	%edx
	pushl	16(%ebp)
	pushl	12(%ebp)
	pushl	8(%ebp)
	call	_ReadFile@20
	movl	-12(%ebp),%ecx
	addl	%ecx,_CharsRead
	movl	12(%ebp),%edi
	movl	%edi,%esi
	incl	%ecx
_$DoReadLoop:
	dec	%ecx
	je	_$DoReadEndLoop
	lodsb
	stosb
	cmpb	$13,%al
	jne	_$DoReadLoop
	dec	%edi
	jmp	_$DoReadLoop
_$DoReadEndLoop:
	cmpb	$26,%al
	je	_$zapCtrlZ
_$DoReadOut:
	mov	-12(%ebp),%eax
	sub	%edi,%esi
	sub	%esi,%eax
	popl	%edi
	popl	%esi
	leave
	ret
_$zapCtrlZ:
	dec	%edi
	jmp	_$DoReadOut
	.align	2,0x90
;**************************************
; allocate called from alloc.c
; This function is called more than 200.000 times in compiles of large
; files. It tests quickly if a cheap allocation (without calling malloc)
; can be done.
;**************************************
	.globl	_allocate
	.type	_allocate,function
_allocate:
	movl	4(%esp),%eax
	movl	8(%esp),%edx
	movl	_arena(,%edx,4),%ecx
; roundup size of block to be allocated
	addl	$7,%eax
	andl	$0xfffffff8,%eax
	movl	8(%ecx),%edx
	leal	(%edx,%eax),%edx
; test if space available
	cmpl	4(%ecx),%edx
	ja 	_$allocateFail
; Test OK. add to ap->avail and return the old value
	addl	$8,%ecx
	xadd	%eax,(,%ecx)
	ret
_$allocateFail:
; No more space available. Call allocate slow for searching the free
; blocks list and (eventually) call malloc
	movl	%eax,4(%esp)
	jmp	_allocateslow
	.extern	_allocateslow
	.extern	_arena
	.extern	_ReadFile@20
	.extern	_GetTickCount@0
	.bss
	.extern	_CharsRead
	.extern	_ReadTime
	.data
	.extern	_nlist
