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?

Recommended Answers

All 3 Replies

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.

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.

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 !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.