This program checks if a given integer is a prime number. You are to design the processor's
Fantastic news! We've Found the answer you've been seeking!
Question:
This program checks if a given integer is a prime number. You are to design the processor's FSMD, Datapath and control unit to execute this algorithm. The pseudocode is given below:
IsPrime(n): if n <= 1:
return False if n <= 3:
return True
# Check divisibility by 2 or 3
if n % 2 == 0 or n % 3 == 0:
return False
# Check divisibility by numbers from 5 up to the square root of n
for i from 5 to sqrt(n) + 1:
if n % i == 0:
return False
return True
sqrt(n): if n < 0:
return -1 if n <= 1:
return n x = n while True:
x0 = x
x = (x + n // x) // 2
if abs(x - x0) < 1:
return x
Related Book For
Computer Organization and Design The Hardware Software Interface
ISBN: 978-0124077263
5th edition
Authors: David A. Patterson, John L. Hennessy
Posted Date: