User Tools

Site Tools


haas:spring2010:asm_primes

Overview

Before we begin our exploration into assembly language, I would like for you to write a C program that accomplishes the following (we will be creating a program of similar functionality in assembly language):

  • Prompts the user to enter an ending value (integer).
  • Displays a list of numbers from 2 through that ending value (inclusive).
  • After each number, display whether or not that number is “prime” or “composite”.

Some tips:

  • Keep it simple. Don't do any math tricks. This isn't about performance as much as it is about having a simple functional program we can compare to its assembly counterpart.
  • A Prime number is one which is divisible only by 1 and itself (no other factors).
  • A Composite number, therefore, is one which has other factors.

For example:

  • 17 is a prime number. You can only evenly divide it by 1 and 17.
  • 15 is a composite number. It is divisible by 1, 3, 5, and 15.
  • 2 is the only even prime number. All others are composite (they are divisible by 2).

Example output

lab46:~$ ./my_prime
Enter upper range: 12
2: Prime
3: Prime
4: Composite
5: Prime
6: Composite
7: Prime
8: Composite
9: Composite
10: Composite
11: Prime
12: Composite
lab46:~$ 

The goal is, once we have a working C version, to eventually create an assembly version that works the same way and produces identical output.

Often times it is extremely beneficial to have a working algorithm in a higher level language as a basis for comparison when delving into a new programming environment.

Verifying

When you are done, and prior to submitting, you may want to verify that your code will work when evaluated.

To do so, you can follow the following steps–

does it compile?

To wit:

lab46:~/src/asm/prime$ gcc -o prime prime.c
lab46:~/src/asm/prime$ 

If, when compiling it with gcc, it just returns a command-line, without saying anything, you will likely be okay.

compare output

After you've successfully compiled it, you will want to check your program's output against the master.

To check this, do the following:

lab46:~/src/asm/prime$ ./prime < /var/public/asm/prime_input.txt > output.txt
lab46:~/src/asm/prime$ diff /var/public/asm/prime_output.txt output.txt
lab46:~/src/asm/prime$ 

Again, if all you get is your prompt back, then your program's output matches the master copy, and all should be good in the universe… assuming there are no further logic problems with your program, you should consider your program ready for submission.

If not, then take the necessary steps to bring your program into alignment before submitting. You only get one chance to submit.

Submission

When you are finished with your program and ready to submit, you will want to copy it into your data/submit directory, before the deadline.

Assuming a program name of prime.c, one could submit it as follows:

lab46:~/src/asm/prime$ cp prime.c ~/data/submit

And that's it! Remember to submit your source code only, and make sure it compiles and runs.

After about a minute, assuming everything goes according to plan, you should have a results.asm.projects file appear inside ~/data, which you can cat to see your results.

Your program will be compared against the master, with a randomly chosen prime number at some range starting in the triple digits.

haas/spring2010/asm_primes.txt · Last modified: 2013/12/22 22:43 by 127.0.0.1