1b1994897Sopenharmony_ci# Copyright (c) 2021-2022 Huawei Device Co., Ltd. 2b1994897Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 3b1994897Sopenharmony_ci# you may not use this file except in compliance with the License. 4b1994897Sopenharmony_ci# You may obtain a copy of the License at 5b1994897Sopenharmony_ci# 6b1994897Sopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 7b1994897Sopenharmony_ci# 8b1994897Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software 9b1994897Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 10b1994897Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11b1994897Sopenharmony_ci# See the License for the specific language governing permissions and 12b1994897Sopenharmony_ci# limitations under the License. 13b1994897Sopenharmony_ci 14b1994897Sopenharmony_ci.function u1 main(){ 15b1994897Sopenharmony_ci movi v0, 45000 16b1994897Sopenharmony_ci movi v1, 256 17b1994897Sopenharmony_ci movi v2, 46080000 18b1994897Sopenharmony_ci call test, v0, v1, v2, v0 19b1994897Sopenharmony_ci return 20b1994897Sopenharmony_ci} 21b1994897Sopenharmony_ci 22b1994897Sopenharmony_ci.function i32 test(i32 a0, i32 a1, i32 a2){ 23b1994897Sopenharmony_ci movi v3, 0 #sum 24b1994897Sopenharmony_ci movi v4, 0 #loop counter 25b1994897Sopenharmony_ci ldai 0 26b1994897Sopenharmony_ciloop: 27b1994897Sopenharmony_ci movi v5, 0 #loop2_counter 28b1994897Sopenharmony_ci jeq a0, loop_exit 29b1994897Sopenharmony_ci lda v5 30b1994897Sopenharmony_ciloop2: 31b1994897Sopenharmony_ci jeq a1, loop2_exit 32b1994897Sopenharmony_ci call.short bitsinbyte, v5, v0 33b1994897Sopenharmony_ci add2 v3 34b1994897Sopenharmony_ci sta v3 35b1994897Sopenharmony_ci inci v5, 1 36b1994897Sopenharmony_ci lda v5 37b1994897Sopenharmony_ci jmp loop2 38b1994897Sopenharmony_ciloop2_exit: 39b1994897Sopenharmony_ci inci v4, 1 40b1994897Sopenharmony_ci lda v4 41b1994897Sopenharmony_ci jmp loop 42b1994897Sopenharmony_ciloop_exit: 43b1994897Sopenharmony_ci lda v3 44b1994897Sopenharmony_ci jne a2, assert_err 45b1994897Sopenharmony_ci ldai 0 46b1994897Sopenharmony_ci return 47b1994897Sopenharmony_ciassert_err: 48b1994897Sopenharmony_ci ldai 1 49b1994897Sopenharmony_ci return 50b1994897Sopenharmony_ci} 51b1994897Sopenharmony_ci 52b1994897Sopenharmony_ci.function i32 bitsinbyte(i32 a0){ 53b1994897Sopenharmony_ci movi v1, 1 #m 54b1994897Sopenharmony_ci movi v2, 0 #c 55b1994897Sopenharmony_ciloop: 56b1994897Sopenharmony_ci ldai 0x100 57b1994897Sopenharmony_ci jle v1, loop_exit 58b1994897Sopenharmony_ci and a0, v1 59b1994897Sopenharmony_ci jnez if_b 60b1994897Sopenharmony_ciendif: 61b1994897Sopenharmony_ci lda v1 62b1994897Sopenharmony_ci shli 1 63b1994897Sopenharmony_ci sta v1 64b1994897Sopenharmony_ci jmp loop 65b1994897Sopenharmony_ciloop_exit: 66b1994897Sopenharmony_ci lda v2 67b1994897Sopenharmony_ci return 68b1994897Sopenharmony_ciif_b: 69b1994897Sopenharmony_ci inci v2, 1 70b1994897Sopenharmony_ci jmp endif 71b1994897Sopenharmony_ci} 72