1 /*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This software was developed by the Computer Systems Engineering group
6 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
7 * contributed to Berkeley.
8 *
9 * %sccs.include.redist.c%
10 */
11
12 #ifndef lint
13 static char copyright[] =
14 "@(#) Copyright (c) 1992, 1993\n\
15 The Regents of the University of California. All rights reserved.\n";
16 #endif /* not lint */
17
18 #ifndef lint
19 static char sccsid[] = "@(#)divrem.c 8.1 (Berkeley) 06/04/93";
20 #endif /* not lint */
21
22 #include <stdio.h>
23
main()24 main()
25 {
26 union { long long q; unsigned long v[2]; } a, b, q, r;
27 char buf[300];
28 extern long long __qdivrem(unsigned long long, unsigned long long,
29 unsigned long long *);
30
31 for (;;) {
32 printf("> ");
33 if (fgets(buf, sizeof buf, stdin) == NULL)
34 break;
35 if (sscanf(buf, "%lu:%lu %lu:%lu",
36 &a.v[0], &a.v[1], &b.v[0], &b.v[1]) != 4 &&
37 sscanf(buf, "0x%lx:%lx 0x%lx:%lx",
38 &a.v[0], &a.v[1], &b.v[0], &b.v[1]) != 4) {
39 printf("eh?\n");
40 continue;
41 }
42 q.q = __qdivrem(a.q, b.q, &r.q);
43 printf("%lx:%lx /%% %lx:%lx => q=%lx:%lx r=%lx:%lx\n",
44 a.v[0], a.v[1], b.v[0], b.v[1],
45 q.v[0], q.v[1], r.v[0], r.v[1]);
46 printf(" = %lX%08lX / %lX%08lX => %lX%08lX\n\
47 = %lX%08lX %% %lX%08lX => %lX%08lX\n",
48 a.v[0], a.v[1], b.v[0], b.v[1], q.v[0], q.v[1],
49 a.v[0], a.v[1], b.v[0], b.v[1], r.v[0], r.v[1]);
50 }
51 exit(0);
52 }
53