 #
 # some routines for general usage
 #
	.file	"helper.s"
	.globl	_strlen
	.align	4
_strlen::
	movd	4(sp),r1
	movqd	0,r0		# length of string
lp:	cmpqb	0,0(r1)		# is it zero?
	beq	out		# it is, get out
	addqd	1,r0		# increment value
	addqd	1,r1		# increment pointer
	br	lp		# and loop
out:	ret	$0
	
	.globl	_blkcopy
	.align	4
_blkcopy::
	movd	12(sp),r0	# get length
	movd	8(sp),r1	# get source address
	movd	4(sp),r2	# get destination address
	movsw
	ret	$0

	####################################################


	.globl	_hs2net,_net2hs,_hl2net,_net2hl,_cksum
	.align	4
_hs2net::
_net2hs::
	movb	4(sp),tos	# get first byte
	movb	6(sp),tos	# get second byte
	movzwd	tos,r0		# and return both
	ret	$0

	.align	4
_hl2net::
_net2hl::
	movb	4(sp),tos	# get first byte
	movb	6(sp),tos	# get second byte
	movb	8(sp),tos	# get third byte
	movb	10(sp),tos	# get fourth byte
	movd	tos,r0		# return all
	ret	$0

 # cksum(ptr,num) takes a pointer and the number of
 # words (2 bytes) to sum
 # It uses one's complement arithmetic and then
 # complements the sum

	.align	4
_cksum::
	movd	4(sp),r1	# get pointer to bufer
	movw	8(sp),r2	# number of words to check
	movqd	0,r0		# zero r0
ckl:	addw	0(r1),r0	# add to r0
	addcw	$0,r0		# add carry to extend
	addqd	2,r1		# move to next poitner
	acbw	-1,r2,ckl	# loop for more
	comw	r0,r0		# DEBUG complement and return
	ret	$0
