-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmult19.a
More file actions
31 lines (27 loc) · 728 Bytes
/
mult19.a
File metadata and controls
31 lines (27 loc) · 728 Bytes
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
; mult19.a
; from Australian Personal Computer, Aug 1984: https://archive.org/details/apc_1984_08/page/115/mode/2up?q=6502+multiplication
; also from Neil Parker: https://www.llx.com/Neil/a2/mult.html
;
; 8 bit x 8 bit unsigned multiply, 16 bit result
; Average cycles: 185
; 18 bytes
NUM1 = $02
NUM2 = $03
RESULT = $04
* = $0200
; calculate NUM1 * NUM2
; Result in A (high byte) and RESULT (low byte)
mult
lda #0 ; Initialize RESULT to 0
ldx #8 ; There are 8 bits in NUM2
L1
lsr NUM2 ; Get low bit of NUM2
bcc L2 ; 0 or 1?
clc ; If 1, add NUM1
adc NUM1
L2
ror ; "Stairstep" shift (catching carry from add)
ror RESULT
dex
bne L1
rts