-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ro.mima
73 lines (70 loc) · 930 Bytes
/
Ro.mima
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
.reg ACC 0
.reg IAR init
9
8
7
6
5
4
3
2
1
.org 0x00040
8
.org 0x00080 ;; tempVars
i: .lit 0
k: .lit 0
maxIndex: .lit 0
max: .lit 0
negOne: .lit -1
one: .lit 1
temp: .lit 0
.org 0x00100 ;start
init:
LDV 0x40
STV i
iHead:
LDV i
JMN end
iBody:
LDV i ;
STV maxIndex ; max index is current one
LDIV maxIndex ; A[i]
STV max ; write in max
LDV i
STV k ; init k
kHead:
LDV k
JMN afterLoop
kBody:
LDV max
NOT ; ones coplement
ADD one ; twos complement
STV temp ; -max in temp
LDIV k ; A[k]
ADD temp ; A[k] - max
JMN kAfter; >=0 ==> A[k] > max
LDV k
STV maxIndex
LDIV maxIndex
STV max
kAfter: ; k--
LDV k
ADD negOne
STV k
JMP kHead ; next loop
afterLoop:
; swap
LDIV i
STV temp ; A[i] -> temp
LDV max
STIV i ; A[i] = max
LDV temp
STIV maxIndex ; A[maxIndex] = temp
iAfter: ; i--
LDV i
ADD negOne
STV i
JMP iHead ; next loop
end:
HALT