Re: LZ: manipulations
[Prev][Next][Index][Thread]
>Yes, but the number you want to multiply with must be
>a constant. You can't for example multiply a*b. Then you
>must use a multiply routine.
>
>--=20
>Real name: Jimmy M=E5rdell
>Email....: mailto:mja@algonet.se
>IRC-name.: Yarin
>WWW......: http://www.algonet.se/~mja
>
>
why not just do a routine like...
if the number you are multiplying is in adress 40H and the number multiplied
by is in 41h and the result is in 42h then do something like this:
ld hl,40h ; get address of number to be multiplied
ld a,(hl) ; get number
inc hl ; get next adress
ld b,(hl) ; get multiplier =20
next: add a,a ; number =3D number * 2
dec b ; decrement the multiplier
jr nz,next ; if multiplier is not zero goto next:
inc hl ; multiplier is zero get next adress
ld (hl),a ; load into that adress the result
halt ; stop
granted that program has its bugs like the bigger the number is.. ie 2* 665
would take alot of time to do but it could be improved so that the smaller
number becomes the multiplier (2*3 and 3*2 both equal 6) but hey that is a
quick simple program ;). and the main loop only takes like 12-16 clock
cycles i think.. im just a budding programer but i think that works :)
References: