DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Assembly (http://www.daniweb.com/forums/forum125.html)
-   -   Two code snippets that should have the same effect but don't (http://www.daniweb.com/forums/thread196653.html)

Recursive Jun 9th, 2009 4:31 am
Two code snippets that should have the same effect but don't
 
I think these two code snippets should have the same effect. The current code is
add esp, 36
pop esi
sub esp, 40
which works. I want to replace it with
mov esi, [esp + 36]
but replacing my current code with this code has a different effect. Are these two snippets equivalent?

sysop_fb Jun 10th, 2009 9:00 am
Re: Two code snippets that should have the same effect but don't
 
No the first one is popping whatever is on the stack at that location, the second one is considering whatever is at that position in the stack to be a memory address and you're saying whatever is at that address copy it into esi.
Consider stepping through the code through a debugger.

mathematician Jun 25th, 2009 7:45 pm
Re: Two code snippets that should have the same effect but don't
 
They look as though they should do the same thing. The only thing I can think of is if you have got an "assume ss" somewhere. Other than that, you could try posting a larger code fragment so that we can see it in context.

wildgoose Jun 26th, 2009 12:16 pm
Re: Two code snippets that should have the same effect but don't
 
Are you preserving ebx, esi, edi ? These three registers are to be protected in function calls.

Your two code snippets do load the same value from memory though!

In Win32 The Stack Selector SS:, Data Selector DS: and Extra Selector ES: are typically set the same from the application point of view. In the older 16-bit Operating systems, the 'Segment Registers' as they were called then were almost always different !


All times are GMT -4. The time now is 6:54 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC