Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

thiscall

Posted on 2004-04-26
4
Medium Priority
?
360 Views
Last Modified: 2012-06-21
Just a quick question, if you code a member function in assembler, the this pointer is passed as ecx.

Can you use ecx then without the need to save it to the stack and restore it when your finished?

Or will the compiler assume that since it already put the this pointer into ecx, it can skip that on the next member function call.

Is there any way to tell? I looked at the disassembly but didn't see anything conclusive one way or the other.

thanks,
-Sandra
0
Comment
Question by:Sandra-24
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 11

Assisted Solution

by:dimitry
dimitry earned 100 total points
ID: 10922812
Note: I am talking about VC++ 6.0. Another compiler may behave different.
ECX has a 'this' pointer. And compuler push into the stack but only to use later as 'this'.
It is not restored before return.
So Compiler doesn't suppose that ECX will contain 'this' value after return from your member function, but
it is good "style" to push and pop all registers you are going to change temporarely in your function.
0402794     lea         ecx,[ebp-24h]                                      ; << ecx has 'this' pointer
00402797   call        @ILT+25(Move::PrintData) (0040101e)

0
 
LVL 22

Accepted Solution

by:
grg99 earned 200 total points
ID: 10927509
It depends on the compiler, and the optimization level.   Usually at a low optimization level, the compiler doesnt keep much info in registers, so it *may* be possible to mangle ecx.

At higher optimization levels, the compiler may switch to keeping frequently used values in registers, so ecx may not be mangleable.

The only way to make sure is to read the compiler's "calling conventions" chapter and see what it expects.

0
 
LVL 3

Author Comment

by:Sandra-24
ID: 10932333
Well I read through the VC docs again on calling conventions and didn't find any help one way or another. I also followed a few threads on thiscall and assembly but didn't learn anything of value. I checked google again but also found nothing. I suppose the best is just be safe and save the value of ecx on the stack and restore it after.

thanks,
-Sandra
0
 
LVL 3

Assisted Solution

by:Dancie
Dancie earned 200 total points
ID: 10937744
The only registers that are saved across functions with VC are:
ebp,esi,edi,and ebx. I have never seen a compiler for windows or
unix that does it differently. This seems to be a global standard for all
compilers. The use of ecx may have been a choise of the compiler to
make an optimization, or just a random choise.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What monsters are hiding in your child's room? In this article I will share with you a tech horror story that could happen to anyone, along with some tips on how you can prevent it from happening to you.
If something goes wrong with Exchange, your IT resources are in trouble.All Exchange server migration processes are not designed to be identical and though migrating email from on-premises Exchange mailbox to Cloud’s Office 365 is relatively simple…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question