Advertisement
jareth_2005

Mul16

Apr 3rd, 2022
1,646
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;********************************************
  2. ;*                                          *
  3. ;*  MULT16                                  *
  4. ;*                                          *
  5. ;*  16bit multiplication     32bit result   *
  6. ;*                                          *
  7. ;*  /1  Variable a     16-bit               *
  8. ;*  /2  Variable b     16 bit               *
  9. ;*  /3  Destination    32 bit               *
  10. ;*                                          *
  11. ;********************************************
  12.             .macro MULT16
  13.  
  14.             lda \2
  15.             pha
  16.             lda \2 + 1
  17.             pha
  18.  
  19.             lda #0      ;initialize result to 0
  20.             sta \3 + 2
  21.             ldx #16     ;there are 16 bits in num2
  22. @l1
  23.             lsr \2 + 1  ;get low bit of num2
  24.             ror \2
  25.             bcc @l2     ; 0 or 1?
  26.  
  27.             tay         ; if 1, add num1 (hi byte of result is in a)
  28.             clc
  29.             lda \1
  30.             adc \3 + 2
  31.             sta \3 + 2
  32.  
  33.             tya
  34.             adc \1 + 1
  35. @l2
  36.             ror         ;"stairstep" shift
  37.             ror \3 + 2
  38.             ror \3 + 1
  39.             ror \3
  40.  
  41.             dex
  42.             bne @l1
  43.  
  44.             sta \3 + 3
  45.  
  46.             pla
  47.             sta \2 + 1
  48.             pla
  49.             sta \2
  50.  
  51.             .endm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement