/******************************************************************************
* Jonathan Sawyer
* jonmsawyer AT gmail DOT com
* Oct. 9, 2007
* Arch: Motorola 68HC11 Micro-controller
* Language: C
*
* This calculates the greatest common divisor between two 8-bit unsigned
* integers using Euclid's algorithm.
*/
/* mod
* a: takes an 8-bit unsigned integer
* b: takes an 8-bit unsigned integer
* returns: an unsigned 8-bit integer that is the remainder of division between
* a and b: a / b.
*/
unsigned int mod (unsigned int a, unsigned int b) {
if (a < b) return a;
if (a == b) return 0;
while (a >= b) {
a -= b;
}
return a;
}
/* gcd
* Computes the greatest common divisor of two unsigned integers by Euclid's
* algorithm.
* m: 8-bit unsigned integer (non-negative -- this is important)
* n: 8-bit unsigned integer (non-negative -- this is important)
* returns: greatest common divisor of m and n.
*/
int gcd (unsigned int m, unsigned int n) {
unsigned int r;
while (n > 0) {
r = mod(m, n);
m = n;
n = r;
}
return m;
}
int main() {
unsigned int a = 600;
unsigned int b = 17;
unsigned int c = 0;
c = gcd(a, b);
while (1) { ; }
return 0;
}