Changes

Jump to: navigation, search

Programming:Ultrafast Multiplication

53 bytes removed, 09:17, 7 April 2007
some more little optimization
The following is the fastest possible '''multiplication routine''' (in a little specialised way) for the CPC, coded by [[Prodatron]] for the [[Voyage 1993 Megademo]] and the [[Digital Orgasm]] demo. It works with signed values and is mainly used for 3D graphic calculations. You can change it to HL=HLDE*A L by removing LD A,H in front of every RET command inside the MULxxx sub-routines, but in this case A L has to be positive.
<pre>
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;### MULTI -> Multiplies two signed integer values (A=HLDE*AL/256);### Input HLDE=value1 (signed), AL=value3 value2 (signed);### Output A=HLDE*AL/256 (signed)
;### Destroyed F,BC,DE,HL
MULTI EX DE,HL LD L,A LD H,0MULTAB/512
ADD HL,HL
LD BC,MULTAB
ADD HL,BC
LD C,(HL)
INC HL
RET
;
 
DS -$ MOD 512
 
MULTAB
DEFW MUL000,MUL001,MUL002,MUL003,MUL004,MUL005,MUL006,MUL007,MUL008,MUL009,MUL010,MUL011,MUL012,MUL013,MUL014,MUL015,MUL016,MUL017,MUL018,MUL019,MUL020,MUL021,MUL022,MUL023,MUL024,MUL025,MUL026,MUL027,MUL028,MUL029,MUL030,MUL031,MUL032,MUL033