1 //===------------ udivmodqi4.S - uint8 div & mod --------------------------===//
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-exception
7 //===----------------------------------------------------------------------===//
10 // https://gcc.gnu.org/wiki/avr-gcc#Exceptions_to_the_Calling_Convention, the
11 // prototype is `struct {uint8, uint8} __udivmodqi4(uint8, uint8)`.
12 // The uint8 quotient is returned via R24, and the uint8 remainder is returned
13 // via R25, while R23 is clobbered.
15 //===----------------------------------------------------------------------===//
21 .type __udivmodqi4, @function
24 sub r25, r25 ; Initialize the remainder to zero.
25 ldi r23, 9 ; Only loop 8 rounds for uint8.
32 cp r25, r22 ; Compare with the divisor.
33 brcs __udivmodqi4_loop
34 sub r25, r22 ; Subtract the divisor.
35 rjmp __udivmodqi4_loop
38 com r24 ; The uint8 quotient is returned via R24.
39 ret ; The uint8 remainder is returned via R25.