fast division/multiplication
ZXNet echo conference «code.zx»
From Kirill Frolov → To All 23 March 2001
Press RESET immediately, All!
I'm trying to make a screw driver for IS-DOS (and not only). And here it is necessary
CHS addressing is recalculated in LBA and vice versa. If from CHS to LBA then it turns out
two 16-bit multiplications, and if from LBA to CHS then one multiplication and two 16-bit
division with remainder. And if you remember how long the spec divides 16-bit
numbers
then it becomes scary to think how it will slow down! One division
leaves
only a few thousand cycles, and not much less for multiplication. :-(
You can optimize:
; HLDE=LBA, HL'=track DE'=sectors in a track
LD B, 4
L1 EX DE, HL
ADD HL, HL
EX DE, HL
ADC HL, HL
DJNZ L1
LD B, 28
EXX
LD HL, 0
LD DE, (HEADS*SECTORS)
EXX
L2 EX DE, HL
ADD HL, HL
EX DE, HL
ADC HL, HL
EXX
CCF
JR NC, L3
ADD HL, DE
L3 ADC HL, HL
EXX
DJNZ L2
It turns out about 2 thousand cycles. :-( For ONE operation! :-(
I haven’t tried to look at it with a disassembler yet - is it really like that for every screw driver?
slows down? :-( )
* Originally in CODE.ZX
* Crossposted in ZX.SPECTRUM