• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14.function u1 main(){
15    movi v0, 3
16    movi v1, 9
17    movi v2, 504699
18    call test, v0, v1, v2, v0
19    return
20}
21
22.function i32 test(i32 a0, i32 a1, i32 a2){
23    movi v3, 0           #result
24    mov v4, a0           #loop_counter
25    lda a0
26loop:
27    jgt a1, loop_exit
28    movi v5, 3
29    call.short ack, v5, v4
30    add2 v3
31    sta v3
32    movi v5, 17
33    add v5, v4
34    sta v5
35    call.short fib, v5, v5
36    add2 v3
37    sta v3
38    lda v4
39    muli 3
40    addi 3
41    sta v5
42    lda v4
43    muli 2
44    addi 2
45    sta v6
46    lda v4
47    addi 1
48    sta v7
49    call tak, v5, v6, v7, v5
50    add2 v3
51    sta v3
52    inci v4, 1
53    lda v4
54    jmp loop
55loop_exit:
56    lda v3
57    jne a2, assert_err
58    ldai 0
59    return
60assert_err:
61    ldai 1
62    return
63}
64
65.function i32 ack(i32 a0, i32 a1){
66    lda a0
67    jeqz if1
68    lda a1
69    jeqz if2
70    lda a1
71    subi 1
72    sta v1
73    call.short ack, a0, v1
74    sta v2
75    lda a0
76    subi 1
77    sta v0
78    call.short ack, v0, v2
79    return
80if1:
81    lda a1
82    addi 1
83    return
84if2:
85    lda a0
86    subi 1
87    sta v0
88    movi v3, 1
89    call.short ack, v0, v3
90    return
91}
92
93.function i32 fib(i32 a0){
94    ldai 2
95    jgt a0, if
96    lda a0
97    subi 2
98    sta v0
99    call.short fib, v0, a0
100    sta v1
101    lda a0
102    subi 1
103    sta v0
104    call.short fib, v0, a0
105    sta v2
106    add v1, v2
107    return
108if:
109    ldai 1
110    return
111}
112
113.function i32 tak(i32 a0, i32 a1, i32 a2){
114    lda a1
115    jge a0, if
116    lda a0
117    subi 1
118    sta v0
119    call tak, v0, a1, a2, a0
120    sta v3
121    lda a1
122    subi 1
123    sta v1
124    call tak, v1, a2, a0, a0
125    sta v4
126    lda a2
127    subi 1
128    sta v2
129    call tak, v2, a0, a1, a0
130    sta v5
131    call tak, v3, v4, v5, a0
132    return
133if:
134    lda a2
135    return
136}
137