-
Notifications
You must be signed in to change notification settings - Fork 6
/
omult4.a
69 lines (62 loc) · 1.66 KB
/
omult4.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
59
60
61
62
63
64
65
66
67
68
69
; omult4.a
; from Elite, https://www.bbcelite.com/cassette/main/subroutine/mult3.html
;
; 24 bit x 8 bit sign-magnitude multiply, 32 bit sign-magnitude result
; Numbers are 'sign-magnitude' (top bit is the sign and the rest is the magnitude, i.e. not the same as regular 2's compliment numbers)
; Average cycles: 686.88
; 70 bytes
P = $02 ; input (2 bytes)
Q = $04 ; multiplicand
R = $05 ; temp
T = $06 ; temp
K = $07 ; output (4 bytes)
* = $0200
; Signed multiply (A,P+1,P) * Q
;
; On Exit:
; K: product (4 bytes)
; A: high byte of K
; Carry clear
MULT3
sta R ; remember sign
and #%01111111 ; remove sign
sta K+2 ;
lda Q ;
and #%01111111 ; remove sign
beq MU5 ;
sec ;
sbc #1 ;
sta T ; store multiplier-1
lda P+1 ;
lsr K+2 ;
ror ;
sta K+1 ;
lda P ;
ror ;
sta K ;
lda #0 ;
ldx #24 ; loop counter
MUL2
bcc + ;
adc T ;
+
ror ;
ror K+2 ;
ror K+1 ;
ror K ;
dex ;
bne MUL2 ;
sta T ;
lda R ;
eor Q ;
and #%10000000 ; sign of result
ora T ;
sta K+3 ;
rts ;
MU5
sta K ;
sta K+1 ;
sta K+2 ;
sta K+3 ;
clc ;
rts ;