153797Sbostic /*-
2*61162Sbostic * Copyright (c) 1992, 1993
3*61162Sbostic * The Regents of the University of California. All rights reserved.
453797Sbostic *
553797Sbostic * This software was developed by the Computer Systems Engineering group
653797Sbostic * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
753797Sbostic * contributed to Berkeley.
853797Sbostic *
953797Sbostic * %sccs.include.redist.c%
1053797Sbostic */
1153797Sbostic
1253797Sbostic #ifndef lint
13*61162Sbostic static char copyright[] =
14*61162Sbostic "@(#) Copyright (c) 1992, 1993\n\
15*61162Sbostic The Regents of the University of California. All rights reserved.\n";
1653797Sbostic #endif /* not lint */
1753797Sbostic
1853797Sbostic #ifndef lint
19*61162Sbostic static char sccsid[] = "@(#)divrem.c 8.1 (Berkeley) 06/04/93";
2053797Sbostic #endif /* not lint */
2153797Sbostic
2253797Sbostic #include <stdio.h>
2353797Sbostic
main()2453797Sbostic main()
2553797Sbostic {
2653797Sbostic union { long long q; unsigned long v[2]; } a, b, q, r;
2753797Sbostic char buf[300];
2853797Sbostic extern long long __qdivrem(unsigned long long, unsigned long long,
2953797Sbostic unsigned long long *);
3053797Sbostic
3153797Sbostic for (;;) {
3253797Sbostic printf("> ");
3353797Sbostic if (fgets(buf, sizeof buf, stdin) == NULL)
3453797Sbostic break;
3553797Sbostic if (sscanf(buf, "%lu:%lu %lu:%lu",
3653797Sbostic &a.v[0], &a.v[1], &b.v[0], &b.v[1]) != 4 &&
3753797Sbostic sscanf(buf, "0x%lx:%lx 0x%lx:%lx",
3853797Sbostic &a.v[0], &a.v[1], &b.v[0], &b.v[1]) != 4) {
3953797Sbostic printf("eh?\n");
4053797Sbostic continue;
4153797Sbostic }
4253797Sbostic q.q = __qdivrem(a.q, b.q, &r.q);
4353797Sbostic printf("%lx:%lx /%% %lx:%lx => q=%lx:%lx r=%lx:%lx\n",
4453797Sbostic a.v[0], a.v[1], b.v[0], b.v[1],
4553797Sbostic q.v[0], q.v[1], r.v[0], r.v[1]);
4653797Sbostic printf(" = %lX%08lX / %lX%08lX => %lX%08lX\n\
4753797Sbostic = %lX%08lX %% %lX%08lX => %lX%08lX\n",
4853797Sbostic a.v[0], a.v[1], b.v[0], b.v[1], q.v[0], q.v[1],
4953797Sbostic a.v[0], a.v[1], b.v[0], b.v[1], r.v[0], r.v[1]);
5053797Sbostic }
5153797Sbostic exit(0);
5253797Sbostic }
53