1/*
2Copyright (c) 1990 The Regents of the University of California.
3All rights reserved.
4
5Redistribution and use in source and binary forms are permitted
6provided that the above copyright notice and this paragraph are
7duplicated in all such forms and that any documentation,
8and/or other materials related to such
9distribution and use acknowledge that the software was developed
10by the University of California, Berkeley.  The name of the
11University may not be used to endorse or promote products derived
12from this software without specific prior written permission.
13THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16 */
17#include <picolibc.h>
18
19	.title "H8/500 DIVIDE"
20!! 2 byte integer Divide code for the H8/500
21!!
22!! Steve Chamberlain
23!! sac@cygnus.com
24!!
25!!
26
27!! args in r1 and r4, result in r0/r1
28
29#if __CODE__==32
30#define RET prts
31#else
32#define RET rts
33#endif
34	.global	__divmodhi4
35
36
37__divmodhi4:
38	clr.w	r0
39	tst.w	r1	! neg arg1
40	bpl	PU
41
42
43	neg.w   r1
44NU:	tst.w	r4
45	bmi	NN
46
47NP:	divxu.w	r4,r0
48	neg.w	r0
49	neg.w	r1
50	RET
51
52NN:	neg.w	r4
53	divxu.w	r4,r0
54	neg.w	r0	! get rem sign right
55	RET
56
57
58PU:
59	tst.w	r4
60	bpl	PP
61
62
63PN:	neg.w	r4
64	divxu.w	r4,r0
65	neg.w	r1
66	RET
67
68PP:	divxu.w	r4,r0	! rem in r0, q in r1
69	RET
70
71
72
73