added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / arch / .unmaintained / m68k-native / utility / udivmod32.s
blobecef6b60e385e6235a73c6142355355d86160fdc
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: unsigned 32 bit division/modulus functions for Amiga/m68k
6 Lang: english
7 */
9 #include "machine.i"
11 .balign 4
13 .globl AROS_SLIB_ENTRY(UDivMod32,Utility)
14 .globl AROS_SLIB_ENTRY(UDivMod32_020,Utility)
16 .type AROS_SLIB_ENTRY(UDivMod32,Utility),@function
17 .type AROS_SLIB_ENTRY(UDivMod32_020,Utility),@function
19 AROS_SLIB_ENTRY(UDivMod32_020,Utility):
20 divul.l d1,d1:d0
21 rts
24 This next algorithm is from the ixemul 41.0 source, the file
25 ./ixemul-41.0/gnulib/common.h
28 .balign 4
29 AROS_SLIB_ENTRY(UDivMod32,Utility):
30 movem.l d2-d3,-(sp)
31 cmp.l #0xFFFF,d1
32 bhi.s full_division
33 move.l d1,d3
34 swap d0
35 move.w d0,d3
36 beq.s small_division
37 divu d1,d3
38 move.w d3,d0
39 small_division:
40 swap d0
41 move.w d0,d3
42 divu d1,d3
43 move.w d3,d0
44 swap d3
45 move.w d3,d1
46 movem.l (sp)+,d2-d3
47 rts
49 full_division:
50 move.l d1,d3
51 move.l d0,d1
52 clr.w d1
53 swap d0
54 swap d1
55 clr.w d0
56 moveq #0xF,d2
57 .loop:
58 add.l d0,d0
59 addx.l d1,d1
60 cmp.l d1,d3
61 bhi.s .loopend
62 sub.l d3,d1
63 addq.w #1,d0
64 .loopend:
65 dbra d2,.loop
66 movem.l (sp)+,d2-d3
67 rts