backwards multiply (Re: A86: Sorry Dux. =-|)
[Prev][Next][Index][Thread]
backwards multiply (Re: A86: Sorry Dux. =-|)
On Mon, 10 Aug 1998 19:59:27 -0600 Dux Gregis <assets@eden.rutgers.edu>
writes:
>
>It can't be done backwards :-) It wouldn't be faster if you did,
>because
>you would end up looping more times than needed. You always need one
>value
>shifting right and one value shifting left. The value shifting left
>must
>be 16-bit and preferably the larger of the two (for speed).
>
noooooooooooo!! it has to work!
;hl=de*b
;destroys af,bc
xor a
ld h,a
ld l,a
cp b
jp z,quit
ld c,b ;save for postshift
ld h,d
ld l,e
preshift:
sla b ;find leftmost bit
jp nc,preshift
mainloop:
add hl,hl ;multiply :)
sla b
jp nc,mainloop ;it'll only become 0 when
add hl,de ;a 1 is shifted out
jp nz,mainloop
srl c ;start postshift...
jp c,quit ;this fixes the problem that
postshift: ;you'd get working backwards
add hl,hl ;with even numbers
srl c
jp nc,postshift
quit: ret ;jp z falls through faster that ret z
-josh
_____________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]
References: