News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Just a Question about PUSHing and POINTERs

Started by OceanJeff32, March 25, 2005, 06:08:05 AM

Previous topic - Next topic

OceanJeff32

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
Any good programmer knows, every large and/or small job, is equally large, to the programmer!

sluggy

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.

Petroizki

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.

MichaelW

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.
eschew obfuscation

roticv

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.