If you care about EAX registry, why did you show C++ code instead of assembly? If you come from low level programming background, you have to know that the compiler may decide to use a different registry if EAX isn't spare. Which registry will be chosen highly depends on the compiler being used.
It will be better for you if you stop thinking about assembly at all, at least for now.