Now i'm not asking for a complete easy answer or source, so please take the time to help me. I would like a very detailed explanation telling what to do, I have no idea. I am very confused by stacks, functions, pushing, popping, and all that. I am very new to assembly and my class just completed arrays and went on to functions. In addition, I am just now learning C on the side with assembly while taking another advanced java course. Therefore, I am pretty new to C and its concepts. Although I have read "The C Language" several times and own it.
Here is my assignment:
Write an assembly language function sumPowers such that sumPowers(n) will be the sum 1+2+2^2+2^3+...2^n For example, the value of sumPowers(5) should be 64 (the sum of 1,2,4,8,16,32). Your function is to do no input or output--communicating with the user is to be done by the program that calls your function. Your function is to be callable as though it had the following prototype: int sumPowers(int n); You are, of course, to write a suitable main program that calls sumPowers and to use this main program to test your function. Your main program is to use scanf and printf to do suitable input and output. Note: In all the parts of this assignment you are to follow the usual Pentium conventions for passing parameters, returning values, and using registers.
I'm thinking store the number n in an array that has all its elements decremented by 1 from the original number and set. Reverse it so its in ascending order, or use a loop to initialize an array [1,2,3,4,5...n]. Then use a second array containing the elements: [1,2,2,2,2.....n(replaced with 2] using some kind of compare statement to initialize the elements. So you would compare *p1 (pointer 1 at array 1 which is 1,2,3,4,5....n) to 1. If its not equal to 1, move a 2 into the new empty array 2 which was initialized with n 0s. Then, reset the pointers back to the start of both arrays subtracting N iterations * 4 (because every iteration up an array is 4 bits) to the pointers. Using a third array to store the values; multiply array 2 (1,2,2,2,2...n(replaced by 2)) by itself the number of times array 1 (1,2,3,4,5...n) is pointing to. The logic seems to be all comprehensive, however the stack management involved is not to me.