;	Static Name Aliases
;
;extern void _near andbytes  	   (unsigned char *pdst,unsigned char  *psrc,int  n);
;extern void _near nandbytes 	   (unsigned char  *pdst,unsigned char  *psrc,int  n);
;extern void _near orbytes   	   (unsigned char *pdst,unsigned char  *psrc,int  n);
;extern void _near norbytes  	   (unsigned char  *pdst,unsigned char  *psrc,int  n);
;extern void _near andInvertedbytes(unsigned char *pdst,unsigned char  *psrc,int  n);
;extern void _near xorbytes	   (unsigned char  *pdst,unsigned char  *psrc,int  n);
;extern void _near equivbytes	   (unsigned char  *pdst,unsigned char  *psrc,int  n);
;extern void _near orInvertedbytes (unsigned char *pdst,unsigned char  *psrc,int  n);
;extern void _near andReversebytes (unsigned char *pdst,unsigned char  *psrc,int  n);
;extern void _near orReversebytes  (unsigned char *pdst,unsigned char  *psrc,int  n);
;extern void _near setbytes	   (unsigned char *pdst,unsigned char  *psrc,int  n);
;extern void _near clearbytes	   (unsigned char *pdst,unsigned char  *psrc,int  n);
;extern void _near invertbytes	   (unsigned char *pdst,unsigned char  *psrc,int  n);
;extern void _near noopbytes	   (unsigned char  *pdst,unsigned char  *psrc,int  n);
;
	TITLE   bytes
	.286p
IBM_TEXT	SEGMENT  WORD PUBLIC 'CODE'
	ASSUME	CS: IBM_TEXT
	PUBLIC	_andbytes
_andbytes PROC NEAR
	mov	word ptr cs:opw,9090h		; nop nop
	mov	word ptr cs:opw+2,0c323h	; and ax,bx
	mov	word ptr cs:opb,9090h		; nop nop
	mov	word ptr cs:opb+2,0c322h	; and al,bl
	jmp	common
_andbytes ENDP

	PUBLIC	_nandbytes
_nandbytes PROC NEAR
	mov	word ptr cs:opw,0c323h		; and ax,bx
	mov	word ptr cs:opw+2,0D0F7h	; not ax
	mov	word ptr cs:opb,0c322h		; and al,bl
	mov	word ptr cs:opb+2,0D0F6h	; not al
	jmp	common
_nandbytes ENDP

	PUBLIC	_orbytes
_orbytes PROC NEAR
	mov	word ptr cs:opw,9090h		; nop nop
	mov	word ptr cs:opw+2,0c30Bh	; or ax,bx
	mov	word ptr cs:opb,9090h		; nop nop
	mov	word ptr cs:opb+2,0c30Ah	; or al,bl
	jmp	common
_orbytes ENDP

	PUBLIC	_norbytes
_norbytes PROC NEAR
	mov	word ptr cs:opw,0c30Bh		; or ax,bx
	mov	word ptr cs:opw+2,0D0F7h	; not ax
	mov	word ptr cs:opb,0c30Ah		; or al,bl
	mov	word ptr cs:opb+2,0D0F6h	; not al
	jmp	common
_norbytes ENDP

	PUBLIC	_andInvertedbytes
_andInvertedbytes	PROC NEAR
	mov	word ptr cs:opw,0D0F7h		; not ax
	mov	word ptr cs:opw+2,0c323h	; and ax,bx
	mov	word ptr cs:opb,0D0F6h		; not al
	mov	word ptr cs:opb+2,0c322h	; and al,bl
	jmp	common
_andInvertedbytes	ENDP

	PUBLIC	_xorbytes
_xorbytes	PROC NEAR
	mov	word ptr cs:opw,9090h		; nop nop
	mov	word ptr cs:opw+2,0c333h	; xor ax,bx
	mov	word ptr cs:opb,9090h		; nop nop
	mov	word ptr cs:opb+2,0c332h	; xor al,bl
	jmp	short common
_xorbytes	ENDP

	PUBLIC	_equivbytes
_equivbytes	PROC NEAR
	mov	word ptr cs:opw,0D0F7h		; not ax
	mov	word ptr cs:opw+2,0c333h	; xor ax,bx
	mov	word ptr cs:opb,0D0F6h		; not al
	mov	word ptr cs:opb+2,0c332h	; xor al,bl
	jmp	short common
_equivbytes	ENDP

	PUBLIC	_orInvertedbytes
_orInvertedbytes	PROC NEAR
	mov	word ptr cs:opw,0D0F7h		; not ax
	mov	word ptr cs:opw+2,0c30Bh	; or ax,bx
	mov	word ptr cs:opb,0D0F6h		; not al
	mov	word ptr cs:opb+2,0c30Ah	; or al,bl
	jmp	short common
_orInvertedbytes	ENDP

	PUBLIC	_andReversebytes
_andReversebytes	PROC NEAR
	mov	word ptr cs:opw,0D3F7h		; not bx
	mov	word ptr cs:opw+2,0c323h	; and ax,bx
	mov	word ptr cs:opb,0D3F6h		; not bl
	mov	word ptr cs:opb+2,0c322h	; and al,bl
	jmp	short common
_andReversebytes	ENDP

	PUBLIC	_orReversebytes
_orReversebytes	PROC NEAR
	mov	word ptr cs:opw,0D3F7h		; not bx
	mov	word ptr cs:opw+2,0c30Bh	; or ax,bx
	mov	word ptr cs:opb,0D3F6h		; not bl
	mov	word ptr cs:opb+2,0c30Ah	; or al,bl
	jmp	short common
_orReversebytes	ENDP

common	PROC NEAR
	push	bp
	mov	bp,sp
	push	ds
	push	es
	push	di
	push	si
pdst	EQU	4
psrc 	EQU	8
n	EQU	12
	les	di,pdst[bp]
	lds	si,psrc[bp]
	mov	cx,n[bp]
	xor	dx,dx
	shr	cx,1
	rcl	dx,1		; get carry bit
	jcxz	L2
L1:
	lodsw			; source
	mov	bx,es:[di]	; dest
opw:
;	not	bx		; GXandReverse - will be changed
;	and	ax,bx

	nop
	nop
	xor	ax,bx

	stosw
	loop	L1
L2:
	or	dx,dx
	jz	L3
	lodsb			; source
	mov	bl,es:[di]	; dest
opb:
;	not	bl
;	and	al,bl

	nop
	nop
	xor	al,bl

	stosb
L3:
	pop	si
	pop	di
	pop	es
	pop	ds
	pop	bp
	PUBLIC	_noopbytes
_noopbytes:
	ret
common	ENDP

	PUBLIC	_clearbytes
	PUBLIC	_setbytes
_clearbytes	PROC NEAR
	xor	ax,ax
	jmp	short setcommon
_setbytes:
	mov	ax,0ffffh
setcommon:
	push	bp
	mov	bp,sp
	push	es
	push	di
pdst	EQU	4
psrc 	EQU	8		; ignore this
n	EQU	12
	les	di,pdst[bp]
	mov	cx,n[bp]
	shr	cx,1
	rep	stosw
	adc	cx,cx
	rep	stosb
	pop	di
	pop	es
	pop	bp
	ret
_clearbytes	ENDP

	PUBLIC	_invertbytes
_invertbytes	PROC NEAR
	push	bp
	mov	bp,sp
	push	es
	push	di
pdst	EQU	4
psrc 	EQU	8		; ignore this
n	EQU	12
	les	di,pdst[bp]
	mov	cx,n[bp]
	mov	dx,cx
	and	dx,1
	shr	cx,1
	jcxz	L6
L5:
	mov	ax,es:[di]
	not	ax
	stosw
	loop	L5
L6:
	or	dx,dx
	jz	L7
	mov	al,es:[di]
	not	ax
	stosb
L7:
	pop	di
	pop	es
	pop	bp
	ret
_invertbytes	ENDP
IBM_TEXT	ENDS
	END
