-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathmultover.c.txt
35 lines (29 loc) · 873 Bytes
/
multover.c.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
unsigned nlz(int);
#pragma mc_func nlz { "7c630034" } /* PowerPC cntlzw r3,r3. */
#pragma reg_killed_by nlz /* Set reg kill to "none." */
int main(int argc, char* argv[], char* envp[]) {
// Enter control-c to quit this program.
unsigned x, y, z, m, n, t;
again:
printf("Enter two hex operands\n");
scanf("%x %x", &x, &y);
// ------------------------------ cut ----------------------------------
m = nlz(x);
n = nlz(y);
if (m + n <= 30) goto overflow;
t = x*(y >> 1);
if ((int)t < 0) goto overflow;
z = t*2;
if (y & 1) {
z = z + x;
if (z < x) goto overflow;
}
// z is the correct product of x and y.
// ------------------------------ cut ----------------------------------
printf("%x x %x = %x\n", x, y, z);
goto again;
overflow:
printf("Overflows\n");
goto again;
}