-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.asmy
147 lines (141 loc) · 2.23 KB
/
demo.asmy
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
.orig x3000
set R6 xFDFF
; R0 return value
; R1 charPointer
; R2 targetState
; R3 char
; R4 tmp
; R5 currentState
; R6/R7 reserved
set R4 #0
GETN trap x20
out
ld R3 negChNine
add R0 R0 R3
BRp GETN_DONE
add R0 R0 #9
BRn GETN_DONE
set R3 #0
add R3 R4 R4 ; r3=2r4
add R3 R3 R3 ; r3=4r4
add R3 R3 R4 ; r3=5r4
add R4 R3 R3 ; r4'=10r4
add R4 R4 R0 ; r4'=10r4+in
BR GETN
GETN_DONE ; input n->R4
set R2 #1
shl R2 R4
shl R2 #1
add R2 R2 #-2
; for example, when n=1, R2=b10
; when n=2, R2=b110
; when n=5, R2=b111110
; get nums
add R4 R4 R4 ; 2n numbers
lea R1, nums
inputNums
set R5 #0
NUM trap x20
out
ld R3 negChNine
add R0 R0 R3
BRp NUM_DONE
add R0 R0 #9
BRn NUM_DONE
set R3 #0
add R3 R5 R5 ; r3=2R5
add R3 R3 R3 ; r3=4R5
add R3 R3 R5 ; r3=5R5
add R5 R3 R3 ; R5'=10R5
add R5 R5 R0 ; R5'=10R5+in
BR NUM
NUM_DONE
add R1 R1 #-1
str R5 R1 #0
add R4 R4 #-1
BRp inputNums
set r5 #0
jsr DFS
halt
negChNine .fill #-57
DFS push R7
push R3
push R4
push R1
not R4 R5
and R4 R4 R2
BRnp START; check if state=b11...11110
set r0 #0
pop R1
pop R4
pop R3
pop R7
ret
START ldr R3 R1 #0;getnum1->R3
set R4 #1
shl R4 R3
st R4, save
and R4 R5 R4
BRnp IGNORE_1
ld R4, save
add R5 R5 R4 ;mask
add R1 R1 #2
jsr DFS
add R1 R1 #-2
not R4 R4
and R5 R5 R4 ;mask recover
test r0
BRz SUCCESS
IGNORE_1
ldr R3 R1 #1;getnum2->R3
set R4 #1
shl R4 R3
st R4, save
and R4 R5 R4
BRnp IGNORE_2
ld R4, save
add R5 R5 R4 ;mask
add R1 R1 #2
jsr DFS
not R4 R4
and R5 R5 R4 ;mask recover
test r0
BRz SUCCESS
IGNORE_2
FAIL set r0 #1
pop R1
pop R4
pop R3
pop R7
ret
SUCCESS mov r0 r3
add r0 r0 #-10
BRzp TWO_DIGITS ; >=10
add r0 r0 #10
add r0 r0 #15
add r0 r0 #15
add r0 r0 #15
add r0 r0 #3 ; r0+='0'
out
BR SPACING
TWO_DIGITS
set r0 #49 ; '1'
out
mov r0 r3
add r0 r0 #15
add r0 r0 #15
add r0 r0 #8 ; r0 = r0 - 10 + 48
out
SPACING set r0 #32 ; ' '
out
set r0 #0
pop R1
pop R4
pop R3
pop R7
ret
save .fill #0
.blkw #64
nums .fill #-1
.fill #-1
.end