;	Static Name Aliases
;
	TITLE   bytes

	.386p

n	EQU	8

_TEXT	SEGMENT  DWORD PUBLIC use32 'CODE'
	ASSUME	CS: _TEXT

; All functions take the following arguments:
; function(pdst, psrc, n)
; u_char *pdst;	/* EAX */
; u_char *psrc;	/* EDX */
; int n;	/* EBX */
	PUBLIC	clearbytes_
	PUBLIC	setbytes_

clearbytes_	PROC NEAR
	xor	edx,edx
	jmp	short setcommon
setbytes_:
	mov	edx,-1
setcommon:
;	push	ebp
;	mov	ebp,esp
;	push	es
	push	ecx
	push	edi
;	mov	es,dx		; FP_SEG(pdst)
	mov	edi,eax		; FP_OFF(pdst)
	mov	eax,edx		; 0 or -1 */
	mov	ecx,ebx
	shrd	edx,ecx,2
	shr	ecx,2
	rep	stosd
	shld	ecx,edx,2
	rep	stosb
	pop	edi
	pop	ecx
;	pop	es
;	pop	ebp
	ret
clearbytes_	ENDP

	PUBLIC	invertbytes_
invertbytes_	PROC NEAR
;	push	ebp
;	mov	ebp,esp
;	push	es
	push	ecx
	push	edi
;	mov	es,dx
	mov	edi,eax
	mov	ecx,ebx
	shrd	edx,ecx,2
	shr	ecx,2
	jecxz	L6
L5:
	mov	eax,[edi]
	not	eax
	stosd
	loop	L5
L6:
	shld	ecx,edx,2
	jecxz	L8
L7:
	mov	al,[edi]
	not	al
	stosb
	loop	L7
L8:

	pop	edi
	pop	ecx
;	pop	es
;	pop	ebp
	PUBLIC	noopbytes_
noopbytes_:
	ret
invertbytes_	ENDP

; copyInvertedbytes(u_char *pdst, u_char *psrc, int n)

	PUBLIC	copyInvertedbytes_
copyInvertedbytes_	PROC NEAR
;	push	ebp
;	mov	ebp,esp
;	push	ds
;	push	es
	push	ecx
	push	esi
	push	edi
;	mov	es,dx
	mov	edi,eax
;	mov	ds,cx
	mov	esi,edx

	mov	ecx,ebx

	shrd	edx,ecx,2
	shr	ecx,2
	jz	I_byte
I_L1:
	lodsd
	not	eax
	stosd
	loop	I_L1

	shld	ecx,edx,2
	jz	I_exit
I_byte:
	lodsb
	not	al
	stosb
	loop	I_byte
I_exit:
	pop	edi
	pop	esi
	pop	ecx
;	pop	es
;	pop	ds
;	leave
	ret
copyInvertedbytes_	ENDP

	PUBLIC	orbytes_
orbytes_	PROC NEAR
;	push	ebp
;	mov	ebp,esp
;	push	ds
;	push	es
	push	ecx
	push	esi
	push	edi
;	mov	es,dx
	mov	edi,eax
;	mov	ds,cx
	mov	esi,edx

	mov	ecx,ebx

	shrd	edx,ecx,2
	shr	ecx,2
	jz	or_byte
or_L1:
	lodsd
	or	eax,[edi]
	stosd
	loop	or_L1

	shld	ecx,edx,2
	jz	or_exit
or_byte:
	lodsb
	or	al,[edi]
	stosb
	loop	or_byte
or_exit:

	pop	edi
	pop	esi
	pop	ecx
;	pop	es
;	pop	ds
;	leave
	ret
orbytes_ ENDP
_TEXT	ENDS
	END
