Destroyed registers values in API call

Everything else that doesn't fall into one of the other PB categories.
Denis
Enthusiast
Enthusiast
Posts: 779
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Destroyed registers values in API call

Post by Denis »

Hi,

i always put this asm code at the begining of asm file for PB lib

PUSH ebp
PUSH ebx
PUSH ecx
PUSH edi
PUSH esi

and this one at the end
POP esi
POP edi
POP ecx
POP ebx
POP ebp


even if i don't use these registers. It's because i use some API and i don't know if these registers are destroyed after these call.
I tried to find in the SKD doc but i didn't find.

May i systematically use all previous ASM PUSH/POP :?:


Tks

Denis
A+
Denis
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

Generally, in Windows programming, you should always preserve ebx, esi and edi (ebp and esp too, obviously). And, to avoid problems, it's a good idea to restore them before any API call (if you've modified any of ebx, esi or edi), trashing them before an API call can work in one Windows version and crash the app in another. It's not that Windows API funtions will trash them (they won't, they preserve them, like you), but it makes some assumptions about these registers in some Windows versions.

In PB libs, as you know, you must preserve ecx as well (Windows doesn't care about it, but be careful: any Windows API call can trash ecx). Summing up, if you don't use a register in a PB lib, you don't need to push/pop it, unless, maybe, for ecx if you use API.
El_Choni
Denis
Enthusiast
Enthusiast
Posts: 779
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Post by Denis »

Thanks for your explanation El_Choni.



Denis :wink:
A+
Denis
Post Reply