1# Copyright (c) 2021 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 i64 main(){ 15 movi v1, 10 16 newarr v0, v1, i64[] 17 ldai 0 18main_loop: 19 jge v1, main_ret 20 sta v2 21 call.short fibonacci, v2, v2 22 starr.64 v0, v2 23 lda v2 24 addi 1 25 jmp main_loop 26main_ret: 27 lda v1 28 subi 1 29 ldarr.64 v0 30 return.64 31} 32 33.function i64 fibonacci(i64 a0){ 34 lda a0 35 jnez non_zero 36 return.64 37non_zero: 38 ldai 1 39 jne a0, non_one 40 return.64 41non_one: 42 lda a0 43 subi 1 44 sta a0 45 subi 1 46 sta v1 47 call.short fibonacci, a0, a0 48 sta a0 49 call.short fibonacci, v1, a0 50 add2.64 a0 51 return.64 52} 53