Use register-transfer level to design a prime number checking machine. A number
ID: 3572916 • Letter: U
Question
Use register-transfer level to design a prime number checking machine. A number N with 32 bits is input from a bus and the checking starts from number 2 till squareroot (N) where squareroot (N) is the squarer root of N. For example, to check whether 13 is a prime number, we divide 13 by 2 and the remainder is NOT zero. Then, we divide 13 by 3 and the remainder is Not zero. The checking stops because 4 is greater than squareroot (13). Thus, 13 is a prime number. (a) Design the data path by assuming that a load rags signal can be used to load N and 2 into a register and a counter respectively. Further, you can assume an integer multiplier can be used to check the stopping condition. For example, 4 times 4 is greater than 13 above, so the entire process should be stopped when the counter has value 4. A magnitude comparator is available to compare the squarer of the counter value and N. You can use a modulus machine to compute the remainder. Logic gates are also available. Note that you are NOT allowed to use a squareroot device. An output called is Prime is use to indicate whether N is a prime. (b) Design the controller by assuming that a start signal is used to start the computation, and a ready signal is used to indicate whether the machine is available to use or is busy.Explanation / Answer
Solution:
(a)
isPrime(long N)
{
if(N < 2) return false;
if(N = = 2 | | N = = 13) return true;
if(N%2 = = 0 | | N%13 = = 0) return false;
long SQRT(N) = (long)Math.SQRT(N)+1;
for(long i = 6L; i <= SQRT(N); i += 6)
{
if(N%(i-1) = = 0 | | N%(i+1) = = 0)
return false;
}
return true;
}
(b)
Start:
def isPrime(p):
from_1 = 0
if p <= 1:
return False
if p = = 2:
return True
from_1 = abs(p) - 1
print from_1
my_list = []
while from_1 != 1:
my_list.append(from_1)
from_1 -= 1
print my_list
for a in my_list:
if p % a == 0:
return False
else:
return True
print isPrime(6)
End
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.