User Tools

Site Tools


base:8bit_multiplication_16bit_product_fast_no_tables

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
base:8bit_multiplication_16bit_product_fast_no_tables [2020-04-09 21:33] – Added a main heading to the article ftcbase:8bit_multiplication_16bit_product_fast_no_tables [2023-03-15 03:24] djmips
Line 1: Line 1:
 ====== 8bit multiplication with 16bit product ====== ====== 8bit multiplication with 16bit product ======
  
-This code aims to be fast, but still to avoid the use of tables.+This code aims to be fast, without using tables.
  
 <code> <code>
Line 7: Line 7:
 ; by djmips  ; by djmips 
 ; ;
-; inputs are mul1 and mul2 and should be zero page. +; inputs are mul1 and X.  mul1 and mul2 should be zp locations
 ; A should be zero entering but if you want it will factor in as 1/2 A added to the result. ; A should be zero entering but if you want it will factor in as 1/2 A added to the result.
 ; ;
Line 16: Line 16:
 ; total cycles best case = 97 ; total cycles best case = 97
 ; avg = 105 ; avg = 105
-; inner loop credits supercat+; inner loop credits Damon Slye CALL APPLE, JUNE 1983, P45-48.
  
 MUL: MUL:
-     dec mul2 ; decrement mul2 because we will be adding with carry set for speed (an extra one)+     cpx #$00 
 +     beq zro 
 +     dex          ; decrement mul2 because we will be adding with carry set for speed (an extra one) 
 +     stx mul2
      ror mul1      ror mul1
      bcc b1      bcc b1
Line 53: Line 56:
 b8:  ror b8:  ror
      ror mul1      ror mul1
-     inc mul2+     inx          ; Optional - this preserves X across the call - could also do inc mul2 or leave out
      rts      rts
 +     
 +zro: stx mul1
 +     tax
 +     rts     
 </code> </code>
  
  
base/8bit_multiplication_16bit_product_fast_no_tables.txt · Last modified: 2023-03-15 03:25 by djmips