Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Publishing With Filemaker Pro On The Web

Authors: Maria Langer

1st Edition

0201696657, 978-0201696653

More Books

Students also viewed these Databases questions

Question

How would we like to see ourselves?

Answered: 1 week ago

Question

How can we visually describe our goals?

Answered: 1 week ago

Question

What metaphors might describe how we work together?

Answered: 1 week ago