# z80:OCM

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This is a list of optimised routines for multiplying by a constant. Since multiplying by 2 or any power of 2 only requires doubling the value after multiplying by odd values, this is trivial. Therefore, we only look at multiplying by odd numbers. The list is not complete, but you should eventually see a pattern emerge if you need others:

```   HL_Mul_3:
ld b,h
ld l,c
HL_Mul_5:
ld b,h
ld l,c
HL_Mul_7:
ld b,h
ld l,c
HL_Mul_9:
ld b,h
ld l,c
HL_Mul_11:
ld b,h
ld l,c
HL_Mul_13:
ld b,h
ld l,c
HL_Mul_15_Fast:
ld b,h
ld l,c
ld b,h
ld l,c
HL_Mul_15_Small:
ld b,h
ld l,c
HL_Mul_17:
ld b,h
ld l,c

HL_Mul_19:
ld b,h
ld l,c
HL_Mul_21_Size:
ld b,h
ld l,c
HL_Mul_21_Speed:
ld b,h
ld l,c
ld b,h
ld l,c
HL_Mul_23:
ld b,h
ld l,c
HL_Mul_25:
ld b,h
ld l,c

HL_Mul_27_Size:
ld b,h
ld l,c
HL_Mul_27_Speed:
ld b,h
ld l,c
ld b,h
ld l,c
HL_Mul_29:
ld b,h
ld l,c
HL_Mul_31:
ld b,h
ld l,c
or a
sbc hl,bc
HL_Mul_33:
ld b,h
ld l,c

HL_Mul_35:
ld b,h
ld l,c
HL_Mul_37:
ld b,h
ld l,c
HL_Mul_39_Size:
ld b,h
ld l,c
HL_Mul_39_Speed:
ld b,h
ld l,c
ld b,h
ld l,c

HL_Mul_41:
ld b,h
ld l,c
HL_Mul_43:
ld b,h
ld l,c
HL_Mul_45_Size:
ld b,h
ld l,c
HL_Mul_45_Speed:
ld b,h
ld l,c
ld b,h
ld l,c

HL_Mul_47:
ld b,h
ld l,c
HL_Mul_49:
ld b,h
ld l,c
HL_Mul_51_Size:
ld b,h
ld l,c
HL_Mul_51_Speed:
ld b,h
ld l,c
ld b,h
ld l,c

HL_Mul_53:
ld b,h
ld l,c
HL_Mul_55_Size:
ld b,h
ld l,c
HL_Mul_55_Speed:
ld b,h
ld l,c
ld b,h
ld l,c
HL_Mul_57:
ld b,h
ld l,c

HL_Mul_59:
ld b,h
ld l,c
HL_Mul_61:
ld b,h
ld l,c
HL_Mul_63:
ld b,h
ld l,c
or a
sbc hl,bc
HL_Mul_65:
ld b,h
ld l,c

HL_Mul_67:
ld b,h
ld l,c
HL_Mul_69:
ld b,h
ld l,c
HL_Mul_71:
ld b,h
ld l,c
HL_Mul_73:
ld b,h
ld l,c

HL_Mul_75_Size:
ld b,h
ld l,c
HL_Mul_75_Speed:
ld b,h
ld l,c
ld b,h
ld l,c
HL_Mul_77:
ld b,h
ld l,c
HL_Mul_79:
ld b,h
ld l,c

HL_Mul_81:
ld b,h
ld l,c
HL_Mul_83:
ld b,h
ld l,c
HL_Mul_85_Size:
ld b,h
ld l,c
HL_Mul_85_Speed:
ld b,h
ld l,c
ld b,h
ld l,c

HL_Mul_87_Size:
ld b,h
ld l,c
HL_Mul_87_Speed:
ld b,h
ld l,c
ld b,h
ld l,c
HL_Mul_89:
ld b,h
ld l,c

HL_Mul_255_Size:
ex de,hl
ld h,e
xor a
ld l,a
sbc hl,de
HL_Mul_255_Speed:
xor a
sub l
ld e,a
ld a,l
sbc a,h
ld d,a
ex de,hl
```