Under Visual Studio masm:
mov ecx,270
l1: pop eax
loop l1
push eax
The point of this code is to find out if there is and what is the initial value of ESP
. I try to pop
immediately after the program starts, and experiment that after how many pop
a push
will create some memory reading related error. The result of the experiment is somehow unstable, even with exactly same number for ecx
. Generally, greater than 512 will always(in my limited times of experiments) create an error, less than 128 is always "safe", and values around 250 to 400 will sometimes create error. It seem that there is no initial value for ESP. If there is, my experiment should create some stable result.
OK I run 127 for other 10 more times and now it start to crash. I am trying to experiment more numbers about this.
Let us just say using Windows-x86, on an average moment of starting a program like my experiment's program. How Windows determine what will be the initial value of esp
? Is this difficult to determine(because I could imagine simply put the last address of stack segement in esp
)? Is there a common practice of how to do this?