User Tools

Site Tools


base:fastest_multiplication

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
base:fastest_multiplication [2017-04-17 13:33] – Added heading and credits at start of the article for standardization across the wiki. ftcbase:fastest_multiplication [2017-04-17 13:55] repose
Line 40: Line 40:
 z3=$83 z3=$83
  
-;not shown is routine to make the tables +;Example showing use 
-;also you need to init the pointers' high bytes to the tables+lda #$ff 
 +sta x0 
 +sta x1 
 +sta y0 
 +sta y1 
 +jsr maketables 
 +jsr umult16 
 +;result should be $fffe0001, e.g. as viewed with typical m 0080 monitor command: 
 +;0080 01 00 fe ff 
 + 
 +makesqrtables: 
 +;init zp square tables pointers 
 +lda #>sqrlo 
 +sta p_sqr_lo+1 
 +lda #>sqrhi 
 +sta p_sqr_hi+1 
 +lda #>negsqrlo 
 +sta p_invsqr_lo+1 
 +lda #>negsqrhi 
 +sta p_invsqr_hi+1 
 + 
 +;generate sqr(x)=x^2/
 +      ldx #$00 
 +      txa 
 +      !by $c9   ; CMP #immediate - skip TYA and clear carry flag 
 +lb1:  tya 
 +      adc #$00 
 +ml1:  sta sqrhi,x 
 +      tay 
 +      cmp #$40 
 +      txa 
 +      ror 
 +ml9:  adc #$00 
 +      sta ml9+1 
 +      inx 
 +ml0:  sta sqrlo,x 
 +      bne lb1 
 +      inc ml0+2 
 +      inc ml1+2 
 +      clc 
 +      iny 
 +      bne lb1 
 + 
 +;generate negsqr(x)=(255-x)^2/
 +      ldx #$00 
 +      ldy #$ff 
 +mt1: 
 +      lda sqrhi+1,x 
 +      sta negsqrhi+$100,
 +      lda sqrhi,x 
 +      sta negsqrhi,
 +      lda sqrlo+1,x 
 +      sta negsqrlo+$100,
 +      lda sqrlo,x 
 +      sta negsqrlo,
 +      dey 
 +      inx 
 +      bne mt1 
 +      rts
  
 umult16: umult16:
base/fastest_multiplication.txt · Last modified: 2024-02-13 08:24 by repose