forked from jmatzen/leventhal-6809
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6809_MUL16.s
86 lines (83 loc) · 2.39 KB
/
6809_MUL16.s
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
; Title: 16-bit multiplication
; Name: MUL16
; Purpose: Multiply two unsigned 16-bit words and return a 32-bit unsigned product.
; Entry: TOP OF STACK
; High byte of return address
; Low byte of return address
; High byte of multiplier
; Low byte of multiplier
; High byte of multiplicand
; Low byte of multiplicand
;
; Exit: Product = multiplicand * multiplier
;
; TOP OF STACK
; High byte of high word of product
; Low byte of high word of product
; High byte of low word of product
; Low byte of Low word of product
;
; Time: Approximately 200 cycles
;
; Size: Program 64 bytes
; Data 2 stack bytes
;
MUL16:
;
; CLEAR PARTIAL PRODUCT IN FOUR STACK BYTES
;
LDU ,S ; SAVE RETURN ADDRESS
CLRA ; CLEAR PARTIAL PRODUCT ON STACK
CLRB
STD ,S ; USE BYTES OCCUPIED BY RETURN ADDRESS
PSHS D ; PLUS 2 EXTRA BYTES ON TOP OF STACK
;
; MULTIPLY LOW BYTE OF MULTIPLIER TIMES LOW BYTE
; OF MULTIPLICAND
;
LDA 5,S ; GET LOW BYTE OF MULTIPLIER
LDB 7,S ; GET LOW BYTE OF MULTIPLICAND
MUL ; MULTIPLY BYTES
STB 3,S ; STORE LOW BYTE OF PRODUCT
STA 2,S ; STORE HIGH BYTE OF PRODUCT
;
; MULTIPLY LOW BYTE OF MULTIPLIER TIMES HIGH BYTE
; OF MULTIPLICAND
;
LDA 5,S ; GET LOW BYTE OF MULTIPLIER
LDA 6,S ; GET HIGH BYTE OF MULTIPLICAND
MUL ; MULTIPLY BYTES
ADDB 2,S ; ADD LOW BYTE OF PRODUCT T0 PARTIAL PRODUCT
STB 2,S ;
ADCA #0 ; ADD HIGH BYTE OF PRODUCT PLUS CARRY TO PARTIAL PRODUCT
STA 1,S ; STORE HIGH BYTE OF PRODUCT
;
; MULTIPLY HIGH BYTE OF MULTIPLIER TIMES LOW BYTE
; OF MULTIPLICAND
;
LDA 4,S ; GET HIGH BYTE OF MULTIPLIER
LDB 7,S ; GET LOW BYTE OF MULTIPLICAND
MUL ; MULTIPLY BYTES
ADDB 2,S ; ADD LOW BYTE OF PRODUCT T0 PARTIAL PRODUCT
STB 2,S ;
ADCA 1, ; ADD HIGH BYTE OF PRODUCT PLUS CARRY TO PARTIAL PRODUCT
STA 1,S ;
BCC MULHH ; BRANCH IF N0 CARRY ELSE INCREMENT MOST SIGNIFICANT
; BYTE 0F PARTIAL PRODUCT
INC ,S ;
;
; MULTIPLY HIGH BYTE OF MULTIPLIER TIMES HIGH BYTE
; OF MULTIPLICAND
;
LDA 4,S ; GET HIGH BYTE OF MULTIPLIER
LDB 6,S ; GET HIGH BYTE OF MULTIPLICAND
MUL ; MULTIPLY BYTES
ADDB 1,S ; ADD LOW BYTE OF PRODUCT T0 PARTIAL PRODUCT
ADCA ,S ; ADD HIGH BYTE OF PRODUCT PLUS CARRY TO PARTIAL PRODUCT
; HIGH BYTES OF PRODUCT END UP IN D
; RETURN WITH PRODUCT AT TOP OF STACK
; SAMPLE EXECUTION
; GET LOWER 16 BITS OF PRODUCT FROM STACK
; REMOVE PARAMETERS FROM STACK
; PUT PRODUCT AT TOP OF STACK
; EXIT T0 RETURN ADDRESS