-
Notifications
You must be signed in to change notification settings - Fork 0
/
ds52384_A.asm
99 lines (98 loc) · 2.47 KB
/
ds52384_A.asm
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
.ORIG x3000
BEGIN AND R6, R6, #0
AND R0, R0, #0 ;INITIALIZATION
AND R3, R3, #0
LD R0, CASE1 ;LOAD R0 WITH ADDRESS OF FIRST ENTRY
LD R3, CASE2 ;LOAD R3 WITH ADDRESS OF SECOND ENTRY
LOOP LDR R1, R0, #0 ;R1 IS LOADED WITH VALUE OF FIRST ENTRY
LD R7, BTMSK1 ;BTMSK 1:xFF00
AND R2, R1, R7 ;R2 CONTAINS ISOLATED BITS [15:8] OF FIRST ENTRY
BRnp WHILST ;WHILE THE FIRST ENTRY ID IS NOT 0, CHECK THE NEXT ENTRY
BRz SORT1 ;WHILE THE FIRST ENTRY IS 0, BEGIN HISTOGRAM
WHILST LDR R4, R3, #0 ;R4 CONTAINS THE VALUE AFTER THE FIRST ENTRY
AND R5, R4, R7 ;R5 CONTAINS ISOLATED BITS [15:8] OF THE SECOND ENTRY
BRnp IF ;WHILE THE SECOND ENTRY'S ID IS NOT 0, COMPARE
BRz CHECK ;REACHED END OF LIST, CLEAR AND CHECK NEXT SWAPS
CHECK ADD R6, R6, #0
BRz SORT1
BRnp BEGIN
IF LD R7, BTMSK2 ;BTMSK2: X00FF
AND R2, R1, R7 ;R2 NOW CONTAINS ISOLATED BITS [7:0] OF THE FIRST ENTRY
AND R5, R4, R7 ;R5 NOW CONTAINS ISOLATED BITS [7:0] OF THE SECOND ENTRY
NOT R5, R5 ;SUBTRACT SECOND SCORE FROM FIRST
ADD R5, R5, #1
ADD R5, R5, R2
BRn SWAP ;IF NEGATIVE, SWAP
ADD R3, R3, #1 ;IF POSITIVE OR ZERO, INCREMENT BOTH POINTERS
ADD R0, R0, #1
BRzp LOOP
SWAP STR R1, R3, #0 ;FIRST ENTRY IS STORED IN SECOND ENTRY'S PREVIOUS PLACE
STR R4, R0, #0 ;SECOND ENTRY IS STORED IN FIRST ENTRY'S PREVIOUS PLACE
ADD R0, R0, #1 ;INCREMENT ADDRESS OF FIRST ENTRY
ADD R6, R6, #1 ;ADD ONE TO SWAP COUNTER
ADD R3, R3, #1 ;INCREMENT ADDRESS OF SECOND ENTRY TO POINT DIRECTLY AFTER FIRST
BRnzp LOOP ;SORT AGAIN STARTING FROM NEXT ENTRY
;HISTOGRAM
SORT1 LD R6, BENCH
LD R0, CASE1
LD R5, HIST
LD R4, OFFSET
AND R7, R7, #0
AND R2, R2, #0
SORT LDR R1, R0, #0
LD R3, BTMSK1
AND R3, R1, R3
BRz STRRES
LD R3, BTMSK2
AND R1, R1, R3
ADD R1, R1, R6
BRn STRRES
ADD R0, R0, #1
ADD R7, R7, #1
BRzp SORT
STRRES STR R7, R5, #0
ADD R6, R6, R4
ADD R2, R2, #1
AND R7, R7, #0
ADD R5, R5, #-1
ADD R3, R2, #-5
BRn SORT
LD R0, HIST
LDR R1, R0, #0
LD R2, A
ADD R1, R2, R1
STR R1, R0, #0
ADD R0, R0, #-1
LDR R1, R0, #0
LD R2, B
ADD R1, R2, R1
STR R1, R0, #0
ADD R0, R0, #-1
LDR R1, R0, #0
LD R2, C
ADD R1, R2, R1
STR R1, R0, #0
ADD R0, R0, #-1
LDR R1, R0, #0
LD R2, D
ADD R1, R2, R1
STR R1, R0, #0
ADD R0, R0, #-1
LDR R1, R0, #0
LD R2, F
ADD R1, R2, R1
STR R1, R0, #0
HALT
CASE1 .fill x4005
CASE2 .fill X4006
BTMSK1 .fill XFF00
BTMSK2 .fill X00FF
BENCH .fill #-80
HIST .fill X4004
OFFSET .fill #20
F .fill x4600
D .fill x4400
C .fill x4300
B .fill x4200
A .fill x4100
.END