Re: LZ: Question with programming


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

Re: LZ: Question with programming



Dines Justesen wrote:

> Michael Wyman wrote:
 = 
> > There is no multiplication instruction in assembly language.  Your
 >> instruction mul b, 6 is invalid and will not work.  To do any
 >> multiplication you must use a routine which shifts the multiplier to the
 >> right, tests the carry bit.  If the carry bit is set, you add the
 >> multiplicand to your result (at this point, zero) then shift the
 >> multiplicand one to the left.  Then you repeat until you are done with
your
 >> eight bits.
 >>
 >Thgis is okey if you want to mulytiply to registers, but it is too slow
 >if you want to multiply a register with an immidiate. To do this add
 >a shift and add instructions. To multiply hl by ten do the following
 
 >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? 

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?)

Jeremy Laucks


Follow-Ups: