[A83] Re: Faster Multiplication


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

[A83] Re: Faster Multiplication




Correction - no absolute value table is needed. Also, here is a probably
better version, as both its input and output are in BC:

; Input:  B and C are the numbers to be multiplied
; Output: BC = B * C
;
; Table must be aligned on an $xx00 address. It can be generated at
; runtime with a fairly simple routine.
;
; Table must point to a table of the lsb and msb of squares as follows:
;  .db (-256*-256)/4,(-255)*(-255)/4,(-254*-254)/4,...,(-1*-1)/4
;  and then the msb's of those...
;  .db 0*0/4,1*1/4,2*2/4,...,255*255/4
;  and then the msb's of those...;
;  .db 256*256/4,...,511*511/4
;  and then the msb's of those.
;  .db 0*0/4,1*1/4,2*2/4,...,255*255/4
;  and then the msb's of those...
Multiply:
     ld   a,b
     sub  c
     ld   l,a
     sbc  a,a
     sbc  a,254-(Table>>8)
     ld   h,a
     ld   a,b
     add  a,c
     ld   e,a
     sbc  a,a
     sbc  a,250-(Table>>8)
     ld   d,a
     ld   a,[de]
     sub  [hl]
     ld   c,a
     inc  d
     inc  h
     ld   a,[de]
     sbc  a,[hl]
     ld   b,a
     ret




References: