-
Notifications
You must be signed in to change notification settings - Fork 6
/
omult14.a
58 lines (49 loc) · 1014 Bytes
/
omult14.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
51
52
53
54
55
56
57
58
; omult14.a
; from FastBasic (BASIC interpreter for the Atari 8-bit computers) https://github.com/dmsc/fastbasic/blob/master/src/interp/mul.asm
;
; 16 bit x 16 bit unsigned multiply, 16 bit result (low bytes)
; Average cycles: 575.00
; 43 bytes
* = $0200
multiplicand = $02 ; 2 bytes
tmp1 = $04 ; 2 bytes
tmp2 = $06 ; 2 bytes
tmp3 = $08 ; 1 byte
; On Entry:
; A: multiplier (low)
; X: multiplier (high)
; (multiplicand, multiplicand+1): 2 bytes
; On Exit:
; (tmp1, tmp1+1): 16 bit product
mult
; Store A
sta tmp3
; Get first bit into carry
; lda stack_h, y
lda multiplicand+1
lsr
sta tmp1+1
; lda stack_l, y
lda multiplicand
ror
sta tmp1
lda #0
sta tmp2+1
ldy #16 ; Number of bits
mult_loop
bcc skip_add
clc
adc tmp3
sta tmp2
txa
adc tmp2+1
sta tmp2+1
lda tmp2
skip_add
ror tmp2+1
ror
ror tmp1+1
ror tmp1
dey
bne mult_loop
rts