Re: LZ: Need algorithmic help!!!


[Prev][Next][Index][Thread]

Re: LZ: Need algorithmic help!!!



try |1/x|   y1=abs(x^(-1))


do you have a division routine? if not here's one I dug out of my code
archives... it may or may not work.


; 16-bit x 16-bit Division Subroutine
;
; This subroutine divides the 16-bit quantity in register
; pair DE by the 16-bit quantity in register pair BC.
; The result will be stored in register pair DE and the
; remainder in register pair BC.


dv1616:
	ld	hl,temp		;load hl with symbolic address
	ld	(hl),c		;save the LS byte of the divisor
	inc	hl
	ld	(hl),b		;save the MS byte of the divisor
	inc	hl
	ld	(hl),17		;save the divisors bit count (decimal 17)
	ld	bc,0		;BC will store the partial dividend
 nxtbit:
	ld	hl,count	;Load hl with address of bit count (dec
17)
	ld	a,e		;get the LS byte of the divisor
	rla			;rotate the MSB into carry
	ld	e,a
	mov	a,d		;get the MS byte of the divisor
	rla			;rotate the MSB into carry
	mov	d,a
	dec	(hl)		;decrement the bit count
	ret	z		;return if zero
	ld	a,c		;rotate the MSB of the dividend
	rla			; into the partial dividend
	ld	c,a		;  stored in BC
	ld	a,b
	rla
	ld	b,a
	dec	hl		;point HL to divisor in memory
	dec	hl
	ld	a,c		;get the LS byte of partial dividend
	sub	(hl)		;subtract the LS byte of the divisor
	ld	c,a
	inc	hl
	ld	a,b		;get the MS byte of partial dividend
	sbc	(hl)		;subtract with borrow the divisor
	ld	b,a
	jp	nc,noadd	;if carry=0, do not add divisor to
				; the result of previous subtraction
	dec	hl
	ld	a,c		;The divisor is larger than the partial
	add	(hl)		; dividend, so the divisor must be
	ld	c,a		;  added to the result of the subtraction
	inc	hl		;   so that the previous value of the
	ld	a,b		;    partial dividend is re-established.
	adc	(hl)
	ld	b,a
noadd:
	ccf			;complement the carry
	jp	nxtbit


; * Ram memory variables *


temp:
	dw	0
count:
	db	0




"Do what thou wilt..." Anton Szandor LaVay
<pre>
--
Chris Kuethe <ckuethe@gpu.srv.ualberta.ca> LPGV Electronics and Controls


RSA in 3 lines of PERL:
#!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj
$/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1
lK[d2%Sa2/d0$^Ixp"|dc`;s/\W//g;$_=pack('H*',/((..)*)$/)
</pre>


References: