-
Notifications
You must be signed in to change notification settings - Fork 6
/
mult49.a
54 lines (50 loc) · 961 Bytes
/
mult49.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
; mult49.a
; from Micro 6502 Journal Issue 31 (Dec 1980) p71-74, https://archive.org/details/micro-6502-journal-31/page/n73/mode/2up
; bug fixed
; removed shortcut to 8x16 multiply (resulting in slightly faster and smaller code)
;
; 16 bit x 16 bit unsigned multiply, 32 bit result
; Average cycles: 703
; 43 bytes
* = $0200
acl = $02
ach = $03
xtndl = $04
xtndh = $05
auxl = $06
auxh = $07
; 16 x 16 bit unsigned multiply
;
; On Entry:
; auxl/h: 16 bit multiplier
; X (low),Y (high): 16 bit multiplicand
; On Exit:
; acl, ach, xtndl, xtndh: 32 bit product
mult16x
lda #$10
multi
sty auxl
stx auxh
tay
lda #0
sta xtndl
sta xtndh
mul3x
lda acl
lsr
bcc mul4x ; Bug fix - original listing was missing this line!
lda xtndl
clc
adc auxl
sta xtndl
lda xtndh
adc auxh
sta xtndh
mul4x
ror xtndh
ror xtndl
ror ach
ror acl
dey
bne mul3x
rts