-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmult1.a
40 lines (36 loc) · 1.06 KB
/
mult1.a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
; mult1.a
; from codebase64: https://www.codebase64.org/doku.php?id=base:16bit_multiplication_32-bit_product
; also from '6502 Software Design' by Leo J Scanlon (1980): https://archive.org/details/6502softwaredesi0000scan/page/124/mode/1up
;
; 16 bit x 16 bit unsigned multiply, 32 bit result
; Average cycles: 751
; 38 bytes
multiplier = $02 ; 2 bytes
multiplicand = $04 ; 2 bytes
product = $06 ; 4 bytes
* = $0200
; product = multiplier * multiplicand
mult
lda #0
sta product+2 ; clear upper bits of product
sta product+3
ldx #16 ; set binary count to 16
shift_r
lsr multiplier+1 ; divide multiplier by 2
ror multiplier
bcc rotate_r
lda product+2 ; get upper half of product and add multiplicand
clc
adc multiplicand
sta product+2
lda product+3
adc multiplicand+1
rotate_r
ror ; rotate partial product
sta product+3
ror product+2
ror product+1
ror product
dex
bne shift_r
rts