-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmult45.a
More file actions
64 lines (54 loc) · 1.47 KB
/
mult45.a
File metadata and controls
64 lines (54 loc) · 1.47 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
62
63
64
; mult45.a
; from 'How to program the Apple II Using 6502 Assembly Language', by Randy Hyde, https://archive.org/details/Using_6502_Assembly_Language/page/n197/mode/2up
; tweaked slightly, added necessary initialisation
;
; 16 bit x 16 bit unsigned multiply, 32 bit result
; Average cycles: 695.00
; 38 bytes
mulplr = $02
partial = $04
mulcnd = $06
* = $0200
; The following multiplication routine is a modified version of the multiply routine
; found in the Apple monitor at location $FB63. (Note: this routine is available only
; in the older version of the Apple monitor. It is not available in the newer Autostart
; ROM monitor.)
; usmul- unsigned 16-bit multiplication.
; 32 bit result is returned in locations (mulplr, partial).
usmul
; pha
; tya
; pha
usmul1
lda #0 ; }
sta partial ; } Must initialise partial to zero
sta partial+1 ; }
ldy #$10 ; set up for 16-bit multiply
usmul2
lda mulplr ; test l.o. bit to see if set
lsr
bcc usmul4
clc ; l.o. bit set, add mulcnd to
lda partial ; partial product
adc mulcnd
sta partial
lda partial+1
adc mulcnd +1
sta partial+1
; shift result into mulplr and get the next bit
; of the multiplier into the low order bit of
; mulplr
usmul4
ror partial+1
ror partial
ror mulplr +1
ror mulplr
;
; see if done yet
;
dey
bne usmul2
; pla
; tay
; pla
rts