-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmult50.a
More file actions
61 lines (52 loc) · 2.21 KB
/
mult50.a
File metadata and controls
61 lines (52 loc) · 2.21 KB
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
55
56
57
58
59
60
61
; mult50.a
; from The Merlin 128 Macro Assembler disk, via 'The Fridge': http://www.ffd2.com/fridge/math/mult-div.s
; with an optimisation for speed (changing pha/pla to tax/txa)
; mult2 unrolled once
;
; 16 bit x 16 bit unsigned multiply, 32 bit result
; Average cycles: 534.00
; 55 bytes
; acc*aux -> [acc,acc+1,ext,ext+1] (low,hi) 32 bit result
aux = $02 ; 2 bytes input1
acc = $04 ; 2 bytes input2 } result
ext = $06 ; 2 bytes }
* = $0200
; (acc, acc+1, ext, ext+1) = (aux, aux+1) * (acc, acc+1)
mult
lda #0 ; A holds the low byte of ext (zero for now)
sta ext+1 ; high byte of ext = 0
ldy #8 ; loop counter
clc ;
bcc enter_loop ;
loop
ror ext+1 ; }
ror ; }
ror acc+1 ; } acc_ext >> 1
ror acc ; }
bcc + ; skip if carry clear
clc ; }
adc aux ; }
tax ; remember A }
lda aux+1 ; } ext += aux
adc ext+1 ; }
sta ext+1 ; }
txa ; recall A
+
ror ext+1 ; }
ror ; }
enter_loop
ror acc+1 ; } acc_ext >> 1
ror acc ; }
bcc + ; skip if carry clear
clc ; }
adc aux ; }
tax ; remember A }
lda aux+1 ; } ext += aux
adc ext+1 ; }
sta ext+1 ; }
txa ; recall A
+
dey ; decrement loop counter
bpl loop ; loop back if not done yet
sta ext ;
rts ;