-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmult23.a
More file actions
40 lines (36 loc) · 843 Bytes
/
mult23.a
File metadata and controls
40 lines (36 loc) · 843 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
32
33
34
35
36
37
38
39
40
; mult23.a
; 'tepples' from https://www.nesdev.org/wiki/8-bit_Multiply
;
; 8 bit x 8 bit unsigned multiply, 16 bit result
; Average cycles: 153
; 21 bytes
prodlo = $02
factor2 = $03
* = $0200
; On Entry:
; A: multiplier
; Y: multiplicand
; On Exit:
; A: high byte of product
; prodlo: low byte of product
; X: preserved
mult
; Factor 1 is stored in the lower bits of prodlo; the low byte of
; the product is stored in the upper bits.
lsr ; prime the carry bit for the loop
sta prodlo
sty factor2
lda #0
ldy #8
loop
; At the start of the loop, one bit of prodlo has already been
; shifted out into the carry.
bcc noadd
clc
adc factor2
noadd
ror
ror prodlo ; pull another bit out for the next iteration
dey ; inc/dec don't modify carry; only shifts and adds do
bne loop
rts