Question: Is A Number Prime? Write a function is _ prime that takes a single ( unsigned integer ) argument ( which you can assume is

Is A Number Prime?
Write a function is_prime that takes a single (unsigned integer) argument (which you can assume is >1), and returns 1 if it's a prime number, and 0 otherwise. We aren't going to worry about a clever algorithm here: we will simply check every number from 2 to n-1 to see if it divides n:
def is_prime(n):
i =2
while i < n:
if n % i ==0:
return 0
i +=1
return 1
The div instruction divides unsigned integers and calculates their remainder, but it's unusual. It always divides the value %rdx:%rax (i.e. a 128 bit value with the high bits stored in %rdx and the lower bits in %rax) by its single operand. It always leaves the quotient in %rax and remainder in %rdx.
You can get %rdi divided by %r8 in %rax and remainder in %rdx like this. The first two instructions set %rdx:%rax to the value from %rdi (by putting bunch of leading zeros in %rdx).
mov $0,%rdx
mov %rdi, %rax
div %r8

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!