Homework 3
Overall homework comments:
Program grading will not be based solely on whether or not the programs "works." It will also be based on the organization, structure, and documentation (in the form of program comments) for the submitted work.
Be sure and document your code well. Include:
- Your name in a comment block at the top of every source file.
- A high level description of the problem solved by the program.
- Descriptive comments for each functional block.
- Inline comments that guide the reader and relate the assembly language to the higher level C++ or algorithm being implemented.
Programs
- Write the more general solution for the atoi (ascii to integer) problem. In particular, your program should input a decimal integer string from the user of the form + or - or no leading sign followed by 1 or more characters representing decimal digits (0-9). There will be no more than 10 total digits. Your program should then use a loop to convert the string of ascii characters into the appropriate-valued integer. Your program should then output the integer to the console using the system call for that purpose. Name your source program atoi.s.
- Write a program that inputs a decimal integer from the user and converts that integer into a series of ascii character '1's and '0's as a string in memory and then outputs those characters, one at a time, to the output device. For input, you may use the system call for retrieving an integer from the user.
- A prime number is an integer greater than 1 whose only positive divisors are 1 and the integer itself. The Greek mathematician Eratosthenes developed an algorithm, known as the Sieve of Eratosthenes, for finding all prime numbers less than or equal to a given number, n -- that is, all prime numbers in the range 2 through n. Consider the list of numbers from 2 through n. Two is the first prime number, but the multiples of 2 (4, 6, 8, ...) are not, and so they are corssed out in the list. The first number after 2 that was not crossed out is 3, the next prime. We then cross out from the list all higher multiples of 3 (6, 9, 12, ...). Continuing, we find the _next_ number not crossed out, and find it is 5. So we cross hour all higher multiples of 5 (10, 15, 20, ...). We repeat this procedure until we reach the first number in the list that has not been crossed out and whose square is greater than n. All the numbers that remain in the list are the primes from 2 to n. Write a program that uses this algorithm with a storage in the static global area as the "list" to find all the prime numbers from 2 through n, where n is requested from and input from the user. Name your program sieve.s.