1 //#include "math.h"
2 // Arithmatic functions using add & subtract
3 
mult_u(register unsigned long var1,register unsigned long var2)4 unsigned long mult_u(register unsigned long var1, register unsigned long var2)
5 {
6 
7 	  register unsigned long var_out = 0;
8 
9 	  while (var2 > 0)
10 	  {
11 
12 	  	if (var2 & 0x01)
13 		{
14 			var_out += var1;
15 		}
16 		var2 >>= 1;
17 		var1 <<= 1;
18   }
19 	return var_out;
20 
21 }// mult_u
22 
ldiv_mod_u(register unsigned long a,register unsigned long b,unsigned long * mod)23 unsigned long ldiv_mod_u(register unsigned long a, register unsigned long b, unsigned long * mod)
24 {
25 	register unsigned long div = b;
26 	register unsigned long res = 0;
27 	register unsigned long bit = 0x1;
28 
29 	if (!div)
30 	{
31 		*mod = 0;
32 		return 0xffffffff ; // Div by 0
33 	}
34 
35 	if (a < b)
36 	{
37 		*mod = a;
38 		return 0; // It won't even go once
39 	}
40 
41 	while(!(div & 0x80000000))
42 	{
43 		div <<= 1;
44 		bit <<= 1;
45 	}
46 
47 	while (bit)
48 	{
49 		if (div <= a)
50     		{
51 		      res |= bit;
52 		      a -= div;
53 		 }
54 	    div >>= 1;
55 	    bit >>= 1;
56 	}
57  	 *mod = a;
58   	return res;
59 }// ldiv_mod_u
60 
61 
ldiv_u(register unsigned a,register unsigned b)62 unsigned ldiv_u(register unsigned a, register unsigned  b)
63 {
64 	register unsigned div = b << 16;
65 	register unsigned res = 0;
66 	register unsigned bit = 0x10000;
67 
68 	while (bit)
69   	{
70   		div >>= 1;
71 		bit >>= 1;
72 		if (div < a)
73 		{
74 			res |= bit;
75 			a -= div;
76 		}
77 	}
78 
79 	return res;
80 }
81 
82 
83