Google Answers Logo
View Question
 
Q: Assembly Language Programming ( No Answer,   5 Comments )
Question  
Subject: Assembly Language Programming
Category: Computers > Programming
Asked by: uddin-ga
List Price: $10.00
Posted: 02 Apr 2003 19:39 PST
Expires: 02 May 2003 20:39 PDT
Question ID: 185228
The formula x^2 + x + 41 generates prime numbers >=41. I want to write
an assembly language program that skips the 10 prime numbers >=41 and
then outputs the next 10 primes arranged in a column.

Request for Question Clarification by alexander-ga on 02 Apr 2003 20:29 PST
Any particular CPU architecture? :)

Request for Question Clarification by jeanluis-ga on 03 Apr 2003 04:57 PST
Another very important thing once you have settled on a CPU, is what
assembler... Because, for example, GNU assembler (gas) for Intel x86
is very syntactically different than MASM for the same processor. The
same is true for other platforms as well...

Of course the comment from xarqi is also very important to note... 
:)
--jld

Clarification of Question by uddin-ga on 04 Apr 2003 00:18 PST
Hi,
In response to Xarqi and Froogler. i am aware that this function does
miss some prime numbers, but that is not important. The main idea is
that any value of x would give us some prime number.
To skip the first ten prime numbers would mean, that we would choose a
value of x >= 11
.

Clarification of Question by uddin-ga on 04 Apr 2003 00:20 PST
If you mean the type of processor by CPU architecture, then it is a Pentium. 
Also, the MASM syntax is much better than GAS :)

Clarification of Question by uddin-ga on 09 Apr 2003 16:31 PDT
Even if the function does not generate ALL prime numbers, I just want
the output for x>=11 uptil x=20
Answer  
There is no answer at this time.

Comments  
Subject: Re: Assembly Language Programming
From: xarqi-ga on 02 Apr 2003 23:32 PST
 
Sorry, the formula given does not just generate prime number.  There
is no known formula that does.
Subject: Re: Assembly Language Programming
From: froogler-ga on 03 Apr 2003 10:54 PST
 
Xarqi is right.  The other thing to note is that the formula is also
incomplete for the 1st 10 primes after 41.  It misses, for example,
59.

Froogler
(number theory lover/math major)
Subject: Re: Assembly Language Programming
From: xarqi-ga on 04 Apr 2003 00:49 PST
 
Just to be clear, not only will your function miss some primes, some
of the numbers it generates will *not* be prime.
Subject: Re: Assembly Language Programming
From: uddin-ga on 06 Apr 2003 03:43 PDT
 
xarqi-
I do not know how or why you are assuming that this function will not
generate prime numbers. I wrote up a small program in C++ to check
this function, and at least for the first 25 numbers, my function does
generate a prime number.

here is the C++ code. try it for yourself.
#include <iostream.h>
#include <math.h>


int getValue(int);
bool prime(int n);
bool divisible(int , int );


void main()
{

	int i;

	//function getValue() would return a -1 if
	//a  number is not prime number
	for (i=1; i<=25; i++)
		cout<<getValue(i)<<"  ";
}

int getValue(int x)
{
	int answer;
	answer = (x*x) + x + 41 ;
	if(prime(answer)) //Check for prime number
		return answer;
	else
		return -1;
}


bool prime(int n)                   // function to test if a number n
is prime
{
   int sq_root, i;                  // the square root of n and a
counter i

   sq_root = int(sqrt(float(n)));   // round off the square root of n

   if ((n == 2) || (n == 3)) return true; // doesn't work when sq_root
= 1

   if (divisible(n,2)) return false; // remove the possibility of an
even number

   for (i = 3; i <= sq_root; i+=2)   // only check odd numbers up to 
   {                                 // the square root of n
      if (divisible(n,i))
         return false;
   }
   return true;   // if number got through all the other tests, then
it is prime
}


bool divisible(int num1, int num2) // function to test if num1
divisible by num2
{
   if ((num1 % num2) == 0)
      return true;         // modulo is zero (no remainder), number is
divisible
   else
      return false;        // not divisible
}
Subject: Re: Assembly Language Programming
From: xarqi-ga on 06 Apr 2003 03:58 PDT
 
x=40

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy