The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: OceanJeff32 on March 25, 2005, 06:08:05 AM

Title: Just a Question about PUSHing and POINTERs
Post by: OceanJeff32 on March 25, 2005, 06:08:05 AM
If I start a function by PUSHing all the pointers: ESI, EDI, ESP, EBP, can I use them freely throughout my function/procedure?  For example, I want to use four arrays all together and I could use just two at a time, if I have to...just curious.

Later,

Jeff C
:8)

P.S. Of course, I'll POP them back when I am finished.
:lol
Title: Re: Just a Question about PUSHing and POINTERs
Post by: sluggy on March 25, 2005, 07:46:35 AM
Of course, although you have to be a little more careful with some of them  :wink Value preservation is just a nice thing to implement, it is not a necessity, i.e. when you call a function you should always assume that the eax, ebx, ecx, edx registers will be changed, eax should hold any return value, the rest are just trashed.
Hint: if you are going to preserve values and are using MASM, look at the "USES" macro, it takes care of things for you.
Title: Re: Just a Question about PUSHing and POINTERs
Post by: Petroizki on March 25, 2005, 07:52:10 AM
And keep in mind that by default, MASM uses ebp for it's stack frame. It accesses locals and parameters via ebp, but you don't have to worry about this; if you don't have no references at them in the block of code you modify ebp at.
Title: Re: Just a Question about PUSHing and POINTERs
Post by: MichaelW on March 25, 2005, 09:19:05 AM
If ESP is preserved on the stack, rather than preserving it in another register (EBP is normally used for this) or in a memory variable, and you change the value in it, then you will not be able to recover the preserved value with a simple POP ESP.
Title: Re: Just a Question about PUSHing and POINTERs
Post by: roticv on March 25, 2005, 03:52:07 PM
Quote from: sluggy on March 25, 2005, 07:46:35 AM
....when you call a function you should always assume that the eax, ebx, ecx, edx registers will be changed, eax should hold any return value, the rest are just trashed.
Value in ebx will not be changed. If you use ebx, do preserve it too.