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// for (int i = 0; i < a1; ++i) { 15// a0[i] = i; 16// } 17.function i32 fill(i32[] a0, i32 a1) { 18 movi v0, 0 19 ldai 0 20 starr a0, v0 21 jne a1 , test 22 ldai 0 23 jmp end_test 24test: 25 ldai 1 26end_test: 27 ldai 0 28loop_head: 29 jge a1, loop_exit 30loop_body: 31 starr a0, v0 32 inci v0, 1 33 lda v0 34 jmp loop_head 35 36loop_exit: 37 return 38} 39 40.function i32 main(){ 41 movi v0, 5 #sizeof(array) 42 newarr v1, v0, i32[] 43 44try_begin: 45 movi v0, 10 46 call.short fill, v1, v0 47try_end: 48 49 ldai 1 50 return 51 52catch_block_begin: 53 ldai 0 54 return 55 56.catchall try_begin, try_end, catch_block_begin 57} 58