Two code snippets that should have the same effect but don't

Reply

Join Date: Jun 2009
Posts: 1
Reputation: Recursive is an unknown quantity at this point 
Solved Threads: 0
Recursive Recursive is offline Offline
Newbie Poster

Two code snippets that should have the same effect but don't

 
0
  #1
Jun 9th, 2009
I think these two code snippets should have the same effect. The current code is
  1. add esp, 36
  2. pop esi
  3. sub esp, 40
which works. I want to replace it with
  1. mov esi, [esp + 36]
but replacing my current code with this code has a different effect. Are these two snippets equivalent?
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 39
Reputation: sysop_fb is an unknown quantity at this point 
Solved Threads: 5
sysop_fb sysop_fb is offline Offline
Light Poster

Re: Two code snippets that should have the same effect but don't

 
0
  #2
Jun 10th, 2009
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.
Last edited by sysop_fb; Jun 10th, 2009 at 9:06 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 134
Reputation: mathematician is an unknown quantity at this point 
Solved Threads: 3
mathematician mathematician is offline Offline
Junior Poster

Re: Two code snippets that should have the same effect but don't

 
0
  #3
Jun 25th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Two code snippets that should have the same effect but don't

 
0
  #4
Jun 26th, 2009
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 !
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Assembly Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC