-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmult85.a
More file actions
47 lines (38 loc) · 1.52 KB
/
mult85.a
File metadata and controls
47 lines (38 loc) · 1.52 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
; mult85.a
; from https://github.com/TobyLobster/multiply_test/issues/2
; based on mult2.a
;
; 16 bit x 16 bit unsigned multiply, 32 bit result
; Average cycles: 540.50
; 38 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 #16 ; loop counter. Loop 16 times.
lsr acc+1 ; } acc_ext >> 1
ror acc ; }
bcc loop
add
clc ; }
adc aux ; }
tax ; remember A }
lda aux+1 ; } ext += aux
adc ext+1 ; }
sta ext+1 ; }
txa ; recall A
loop
ror ext+1 ; }
ror ; }
ror acc+1 ; } acc_ext >> 1
ror acc ; }
dey ; decrement loop counter
bcs add ; jump if carry set
bne loop ; loop back if not done yet
sta ext ;
rts ;