# Copyright (c) 2021-2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. .function void insert_zero(i32[] a0, i32 a1) { ldai 0 starr a0, a1 return.void } .function i32 fill(i32[] a0, i32 a1) { movi v0, 0 ldai 0 starr a0, v0 jne a1 , test ldai 0 jmp end_test test: ldai 1 end_test: ldai 0 loop_head: jge a1, loop_exit loop_body: call.short insert_zero, a0, v0 inci v0, 1 lda v0 jmp loop_head loop_exit: return } .function i32 main(){ movi v0, 5 #sizeof(array) newarr v1, v0, i32[] try_begin: movi v0, 10 call.short fill, v1, v0 try_end: ldai 1 return catch_block_begin: ldai 0 return .catchall try_begin, try_end, catch_block_begin }