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