Topic : Pure Assembler Documentation Author : John Kormylo Version : PASM.HYP 1.0 Subject : Documentation/Pure Assembler Nodes : 740 Index Size : 20262 HCP-Version : 3 Compiled on : Atari @charset : atarist @lang : en @default : @help : Help @options : +g -i -s +x +z -t4 @width : 75 View Ref-File[ multiply_by_constant ] /* ****************************************************************** MACRO multiply_by_constant ea,constant Multiplying by powers of two or other constants can often be implemented faster using shift instructions rather than by MULS. Output of this macro will be in register D0. Uses labels bit and shift. ea = long effective address (anything except D0) constant >= 0 ****************************************************************** */ MACRO multiply_by_constant ea,constant IFLT constant ERROR "multiply_by_constant macro: constant must be >= 0" ENDIF IFEQ constant clr.l D0 EXITM ENDIF bit = $4000_0000 ;check bits of constant from left to right shift = -1 ;number of shifts needed (-1 = nothing in D0) REPT 31 IFGE shift shift = shift + 1 IF shift > 8 ;maximum shift = 8 asl.l #8,D0 shift = 1 ENDIF ENDIF IFNE bit & constant IFLT shift move.l ea,D0 ;leftmost non-zero bit in constant ELSE asl.l #shift,D0 add.l ea,D0 ;any other non-zero bits in constant ENDIF shift = 0 ENDIF bit = bit >> 1 ENDM ;end of REPT block IFGT shift asl.l #shift,D0 ENDIF ENDM ;end of MACRO multiply_by_constant