Re: LZ: Question with programming
[Prev][Next][Index][Thread]
Re: LZ: Question with programming
RedLionPA@aol.com wrote:
> >add hl,hl ;*2
> >push hl
> >add hl,hl ;*4
> >add hl,hl ;*8
> >pop de
> >add hl,de ;*8+*2=*10
>
> > This is a lot faster. >>
>
> wouldn't you have to ld hl, de then pop de, not hl?
After having done the first addition hl will hold 2 times the original
value. I then push that to the stack, so the first number on the stack
is 2*hl. Then i multiply hl by 4,so i have 8 times the original value
in hl. When i pop de, i get the original value multiplied by two into
de. So now i have 2*hl in de and 8*hl in hl, so when i add these two
number i get 10*hl, which is what i wanted. This is actually what is
done in the rom to calc the length of the used fp stack and a lot of
other stuff (including aloating mem).
>
> I have another suggestion:
>
> ld b, 10 ; to multiply by ten
> ld de, hl
> Label
> add hl, de
> djnz (Label)
>
> This would be easier to program in, especially if you are multiplying by an
> odd number, which ould require a lot more pushing and popping. I'm probably
> wrong, but it seems to me this would also take up less space. (how much
> space does a label take up?)
A label does not take up any spave at all, it just maeks it easier to
program in asm.
It is possible to make the rutine the way you descreibe, and it is
smaller. But the code i wrote would normally be a lot faster. So if you
want a fast rutine use the shifting thing, and if you want small code
do like you wrote.
--
_______________________________________
Dines Justesen
Email: dines@post1.com or
c958362@student.dtu.dk
WWW : http://www.gbar.dtu.dk/~c958362/
_______________________________________
References: