-
Notifications
You must be signed in to change notification settings - Fork 6
/
mult10.a
50 lines (40 loc) · 1.1 KB
/
mult10.a
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
; mult10.a
; from codebase64 by WhiteFlame: https://www.codebase64.org/doku.php?id=base:8bit_multiplication_16bit_product
;
; 8 bit x 8 bit unsigned multiply, 16 bit result
; Average cycles: 215.08
; 27 bytes
num1 = $02
num2 = $03
num1Hi = $04
* = $0200
;------------------------
; 8bit * 8bit = 16bit multiply
; By White Flame
; Multiplies "num1" by "num2" and stores result in .A (low byte, also in .X) and .Y (high byte)
; uses extra zp var "num1Hi"
; .X and .Y get clobbered. Change the tax/txa and tay/tya to stack or zp storage if this is an issue.
; idea to store 16-bit accumulator in .X and .Y instead of zp from bogax
; In this version, both inputs must be unsigned
; Remove the noted line to turn this into a 16bit(either) * 8bit(unsigned) = 16bit multiply.
mult
lda #0
tay
sty num1Hi ; remove this line for 16*8=16bit multiply
beq enterLoop
doAdd
clc
adc num1
tax
tya
adc num1Hi
tay
txa
loop
asl num1
rol num1Hi
enterLoop ; accumulating multiply entry point (enter with .A=lo, .Y=hi)
lsr num2
bcs doAdd
bne loop
rts