RE: A82: hl*16


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

RE: A82: hl*16




I think that HL is usually multiplied by 16 after it gets data from A (which
is what I usually do):

	ld	h, 0
	ld	l, a		; (usually it gets the num from A)
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl

(55 clocks, 7 bytes)

well, if that's the case, then I have a faster way to just do A * 16 and
store into HL (but is slightly bigger and trashes A)

	rlca
	rlca
	rlca
	rlca
	ld	h,a
	and	%11110000	; get top 4 bits
	ld	l,a
	xor	h		; get low 4 bits
	ld	h,a		; hl = a * 16

(39 clocks, 10 bytes)

also, a way to get HL = A * 32 (and of course you can modify that to be any
power of 2)

	rrca
	rrca
	rrca
	ld	h,a
	and	%11100000	; get top 3 bits
	ld	l,a
	xor	h		; get low 5 bits
	ld	h,a		; hl = a * 32

(35 clocks, 9 bytes)

-crashman

>Hmmm, that should say: "... upper bound on the value hl can have...".
>My advice: stick with the 4 add's.
>
>> If there's an upper bound on the value l can have at that point in the
>> program that is <= 127 it is faster (but will cost you an extra byte) to
>> sll l. In the general case, 4 adds looks pretty tight.
>>
>> -Jeremy
>>
>> On Tue, 30 Nov 1999, Doug Torrance wrote:
>>
>> >
>> > Is there a better way to multiply hl times 16 than adding it to itself
4
>> > times?
>> >
>> > 	add hl,hl
>> > 	add hl,hl
>> > 	add hl,hl
>> > 	add hl,hl
>> >
>> > Thanks!
>> > Doug
>> >
>> >
>> > ______________________________________________________
>> > Get Your Private, Free Email at http://www.hotmail.com
>> >



References: