• 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
15.function i64 main(){
16    ldai 30000
17    sta v1
18    newarr v1, i64[]
19    sta.obj v0
20    call.short init, v0, v1
21    call.short bubblesort, v0, v0
22    lda v1
23    subi 1
24    ldarr.64 v0
25    return.64
26}
27
28.function void init(i64[] a0, i32 a1){
29    movi v2, 0
30loop:
31    lda a1
32    jeqz init_exit
33    subi 1
34    sta a1
35    starr.64 a0, v2
36    inci v2, 1
37    lda v2
38    jmp loop
39init_exit:
40    return.void
41}
42
43.function void bubblesort(i64[] a0){
44    lenarr a0
45    sta v1
46outer:
47    ldai 1
48    sta v2
49    ldai 1
50inner:
51    jge v1, inner_exit
52    sta v3
53    ldarr.64 a0
54    sta v4
55    lda v3
56    subi 1
57    sta v5
58    ldarr.64 a0
59    jlt v4, next
60    call swap, a0, v5, v3, v0
61    movi v2, 0
62next:
63    lda v3
64    addi 1
65    jmp inner
66inner_exit:
67    inci v1, -1
68    lda v2
69    jeqz outer
70    return.void
71}
72
73.function void swap(i64[] a0, i32 a1, i32 a2){
74    lda a1
75    ldarr.64 a0
76    sta v3
77    lda a2
78    ldarr.64 a0
79    starr.64 a0, a1
80    lda v3
81    starr.64 a0, a2
82    return.void
83}
84