User Tools

Site Tools


base:table_generator_routine_for_fast_8_bit_mul_table

Table generator for square table based multiplications

By Graham.

For the fast 8 bit multiplication routine you need a table containing 512 16-bit values of the function f(x)=int(x*x/4).

Since this table needs to be generated quite often, here is a minimum size routine to calculate that table (36 bytes long):

      ldx #$00
      txa
      .byte $c9   ; CMP #immediate - skip TYA and clear carry flag
lb1:  tya
      adc #$00
ml1:  sta multabhi,x
      tay
      cmp #$40
      txa
      ror
ml9:  adc #$00
      sta ml9+1
      inx
ml0:  sta multablo,x
      bne lb1
      inc ml0+2
      inc ml1+2
      clc
      iny
      bne lb1

And for the Seriously fast multiplication by JackAsser you'll also need an extra table containing 512 16-bit values of the function f(x)=int((x-255)*(x-255)/4). This can easily be derived from the above table and generated by adding the following code to Graham's excellent routine:

ldx #$00
ldy #$ff
:
   lda multabhi+1,x
   sta multab2hi+$100,x
   lda multabhi,x
   sta multab2hi,y
   lda multablo+1,x
   sta multab2lo+$100,x
   lda multablo,x
   sta multab2lo,y
   dey
   inx
bne :-
base/table_generator_routine_for_fast_8_bit_mul_table.txt · Last modified: 2016-06-16 13:30 by graham