brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 99aec34 Raw
40 lines · plain
1//===------------ udivmodqi4.S - uint8 div & mod --------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8//9// As described at10// https://gcc.gnu.org/wiki/avr-gcc#Exceptions_to_the_Calling_Convention, the11// prototype is `struct {uint8, uint8} __udivmodqi4(uint8, uint8)`.12// The uint8 quotient is returned via R24, and the uint8 remainder is returned13// via R25, while R23 is clobbered.14//15//===----------------------------------------------------------------------===//16 17	.text18	.align 219 20	.globl __udivmodqi421	.type  __udivmodqi4, @function22 23__udivmodqi4:24	sub     r25, r25           ; Initialize the remainder to zero.25	ldi     r23, 9             ; Only loop 8 rounds for uint8.26 27__udivmodqi4_loop:28	adc     r24, r2429	dec     r2330	breq    __udivmodqi4_end31	adc     r25, r2532	cp      r25, r22           ; Compare with the divisor.33	brcs    __udivmodqi4_loop34	sub     r25, r22           ; Subtract the divisor.35	rjmp    __udivmodqi4_loop36 37__udivmodqi4_end:38	com     r24                ; The uint8 quotient is returned via R24.39	ret                        ; The uint8 remainder is returned via R25.40