-
Notifications
You must be signed in to change notification settings - Fork 8
/
6809_MPRL.s
107 lines (98 loc) · 2.73 KB
/
6809_MPRL.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
.macro CLC
ANDCC #$FE
.endm
.macro SEC
ORCC #1
.endm
; Title: Multiple Precision Rotate Left
; Name: MPRL
;
; Purpose: Rotate left a multi-byte operand N bits.
;
; Entry: TOP OF STACK
; High byte of return address
; Low byte of return address
; Number of bits to rotate
; Length of the operand in bytes
; High byte of operand base address
; Low byte of operand base address
;
; The operand is stored with ARRAY[0] as its
; Least significant byte and ARRAY[LENGTH-1]
; as its most significant byte
;
; Operand rotated left
; Carry Last := bit shifted from least significant position.
;
; Registers Used: A,B,CC,U,X
;
; Time: 50 cycles overhead plus
; ((13 * Length) + 34) cycles per shift
;
; Size: Program 41 bytes
;
MPRL: LDU ,S ; SAVE RETURN ADDRESS
;
; EXIT IF LENGTH OF OPERAND OR NUMBER OF BITS TO ROTATE
; IS ZERO. CARRY IS CLEARED IN EITHER CASE
;
CLC ; CLEAR CARRY INITIALLY
LDA 2,S ; GET NUMBER OF BITS TO ROTATE
BEQ EXITRL ; EXIT IF NUMBER OF BITS TO ROTATE IS ZERO
LDA 3,S ; GET LENGTH OF OPERAND
BEQ EXITRL ; EXIT IF LENGTH OF OPERAND IS ZERO
;
; SAVE POINTER TO MOST SIGNIFICANT BYTE OF OPERAND
;
DECA ; OFFSET OF MOST SIGNIFICANT BYTE =
; LENGTH OF OPERAND - 1
LDX 4,S ; GET BASE ADDRESS OF OPERAND
LEAX A,X ; POINT TO MOST SIGNIFICANT BYTE OF OPERAND
STX ,S ; SAVE POINTER TO MOST SIGNIFICANT BYTE
; ROTATE ENTIRE OPERAND LEFT ONE BIT
; USE PREVIOUS LEAST SIGNIFICANT BIT AS INITIAL
; CARRY INPUT TO PRODUCE ROTATION
RLLP:
LDX ,S ; POINT TO MOST SIGNIFICANT BYTE
LDA ,X ; GET MOST SIGNIFICANT BYTE
LSRA ; SHIFT BIT 0 TO CARRY FOR USE IN ROTATION
LDB 3,S ; GET LENGTH OF OPERAND IN BYTES
LDX ,S ; GET BASE ADDRESS OF OPERAND
;
; SHIFT EACH BYTE OF OPERAND LEFT ONE BIT
; START WITH LEAST SIGNIFICANT BYTE
RLLP1:
ROR ,-X ; SHIFT NEXT BYTE LEFT
DECB
BNE RLLP1 ; CONTINUE THROUGH ALL BYTES
; COUNT NUMBER OF ROTATES
DEC 2,S ; DECREMENT NUMBER OF ROTATES
BNE RLLP ; CONTINUE UNTIL DONE
; REMOVE PARAMETERS FROM STACK AND EXIT
EXITRL:
LEAS 6,S ; REMOVE PARAMETERS FROM STACK
JMP ,U ; EXIT TO RETURN ADDRESS
; SAMPLE EXECUTION
SC4G:
LDA ROTATS ; GET NUMBER OF ROTATES
LDB #SZAY ; GET LENGTH OF OPERAND IN BYTES
LDX AYADR ; GET BASE ADDRESS OF OPERAND
PSHS A,B,X ; SAVE PARAMETERS IN STACK
JSR MPRL ; ROTATE RIGHT
; RESULT OF ROTATING AY=EDCBA087654321H
; 4 BITS IS AY=DCBA987654321EH, C=0
; IN MEMORY AY = 001H
; AY+1 = 032H
; AY+2 = 054H
; AY+3 = 076H
; AY+4 = 098H
; AY+5 = 0BAH
; AY+6 = 0DCH
;
; DATA SECTION
;
SZAY EQU 7 ; LENGTH OF OPERAND IN BYTES
ROTATS: FCB 4 ; NUMBER OF ROTATES
AYADR: FDB AY ; BASE ADDRESS OF OPERAND
AY: FCB $21,$43,$65,$87,$A9,$CB,$ED
END