Coder - Procedures for rapid cell division and multiplication.

KrNews #05
   3) ZX REVIEW has been the procedure of division
badly non-optimal (I have a suspicion
that the one who sent it just copied it
from the book on what a i-8085, not
using additional commands Z-80).

   In DE - dividend, in C - divider
result in HL, the remainder in A.



       ; DIVIDE DE / C = HL


       ORG 40000

       ENT

       LD DE, 768

       LD C, 3

       CALL DIV

       RET

DIV LD B, 16

       LD HL, 0

       LD A, H
DV1 RL E

       RL D

       RLA

       SUB C

       JR NC, DV2

       ADD A, C
DV2 CCF

       RL L

       RL H

       DJNZ DV1

       RET



   4) The point from the same place, at 1.51 times
faster and at less bytes.


             Multiplicand-D

             factor - E

             result - DE


   ; MULTIPLY DxE = DE; 0 <= result <65535


      ORG 40000

      ENT

      LD DE, # FEFF

      CALL MULT

      RET

MULT XOR A

      LD B, 8
MU1 RRA

      RR E

      JR NC, MU0

      ADD A, D
MU0 DJNZ MU1

      RRA

      RR E

      LD D, A

      RET