Lanie Albert
Lanie Albert

Reputation: 1

On super simple CPU: GCD of two inputs on super simple CPU

I was wondering how to find the GCD of two inputs on super simple CPU I have been struggling because there is only 16 bits of memory, so I am not sure how to edit the GCD program to accept two inputs without going beyond the memory capabilities? Could someone help please thank you!

Upvotes: 0

Views: 131

Answers (1)

Yasiel Cabrera
Yasiel Cabrera

Reputation: 608

You could use the euclidean gcd algorithm. If both inputs fit in 16 bits it will work for you This is the pseudocode:

 function gcd(a, b)
      while b ≠ 0
          t := b; 
          b := a mod b; 
          a := t; 
  return a;

Upvotes: 1

Related Questions