Hi every body..i am not sure whats wrong with the code. The program crashes..i dont know why?Please help me out. here is the program requirement:
************************************************** ***************
Overview
Write a program that will generate and print all prime numbers that are less than or equal to a user-defined limit. The program will contain 4 procedures: main and 3 procedures to read the user limit, generate the prime numbers, and print the prime numbers. In addition, the program will have 2 macros to make it more convenient to print text strings and print numeric output.
Details
The program will define an array of 1000 unsigned integers. The main procedure will call each of the other 3 procedures to do the following 3 tasks.
1. This procedure will call the macro to ask the user for an upper limit for the prime numbers. Then procedure will read in and check that the limit is not larger than 7919, the 1000th prime number. If it is larger, the procedure will call the macro to print a warning message that the limit is reset to 7919. Then the procedure will return the limit back to the main procedure.
2. This procedure will fill the array with prime numbers up to the limit. The array is passed into this procedure by address.
Algorithm to generate the prime numbers:
a. initialize the first 2 elements of the array to 2 and 3 (the first 2 prime numbers)
<!--[endif]-->
<!--[if !supportLists]--> b. <!--[endif]-->loop through all odd numbers less than or equal to the limit, starting with the number 5, and test each number this way:
<!--[if !supportLists]--> - Divide the test number by each array element (starting at 3) until the quotient is smaller than the divisor, or until the test number is divisible by the array element.
<!--[if !supportLists]--> - If the test number is divisible by the array element, it is not a prime number. Start the loop again with the next test number.
<!--[if !supportLists]--> - If the quotient becomes smaller than the divisor, the test number is a prime. Put it in the next available spot in the array and update the next available index. (Note that when you first start the loop, the next available index is at the third element of the array)
To see the calculation of the first several prime numbers, click here.
<!--[if !supportLists]--> 3. <!--[endif]-->This procedure will call the macro to print a header, and then print all the prime numbers in the array, 10 numbers per line. To print each prime number, the procedure will call a macro to print the number and a space. Again, the array should be passed by address to this procedure.
In addition to the 4 procedures, the program also has 2 macros.
The first macro makes printing text strings easier. If the name of the macro is ‘print’, the programmer can code: print str1 where str1 is a string which has been defined in the data segment.
The second macro prints a numeric value and a space. If the name of the macro is 'printNum', the programmer can code: printNum eax and the numeric value in eax will be printed followed by a space character.
To think about
- Don't forget to save and restore registers that are used by each macro and each procedure
- In 32-bit mode, the size of each data value on the stack is 32 bits or 4 bytes. This means that to access data in the stack, you should use multiples of 4 for the offset from EBP.
- For the array of prime numbers, you can use word or doubleword data. When you walk the array, just remember to increment by the right number for your data size.
Absolute must haves
- Use the stack to pass input arguments and return values. Except for the main procedure, all other procedures must get input data from the stack and return data through the stack. These procedures should not use any memory variables defined in the .data section, with the exception of string constants used to print to screen.1
- Implement the prime number algorithm given in this lab. Do not use a different algorithm.
- As before, document your program clearly. When it comes to parameter passing through the stack, clear documentation will save you a lot of headaches.
- Programs that do not assemble successfully will receive 1/3 credit at most.
1 Extra Credit (2 pts)
- Implement the procedures so the string constants are passed to them through the stack. This means these procedure does not directly fetch any data from the .data section
First of all, no programming help forum is going to do or debug your assignment for you. Therefore, posting your detailed list of requirements is irrelevant, because programming help forums can only help you with specific programming questions, specific programming errors, or specific programming problems with your code.
Secondly, "The program crashes.." is not a specific statement of a question, error, or problem you need help with. If you can pin down where the problem is occurring in the code and ask a specific question like "after line wwww I am getting xxxx for a value in yyyy instead of zzzz" then someone can probably help you solve the problem with that specific section of code, but just posting all your code and stating that it crashes is not going to get you a helpful response, that is not how programming help forums work.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???