Can you tell what the original C++ source code looks like, in general, for the following setter method?
mov ebp, esp
cmp [ebp + 8], 0
mov eax, [ebp + 8]
mov [ecx + 0], eax
mov eax, 1
mov eax, 0
mov esp, ebp
This code looks a little complicated, but don't panic! We will walk through it slowly. The first two lines of code set up the stack frame:
The next two lines of code compare the value of [ebp + 8] (which we know to be the first parameter) to zero. If [ebp+8] is zero, the function jumps to the label "error". We see that the label "error" sets eax to 0, and returns. We haven't seen it before, but this looks conspicuously like an if statement. "If the parameter is zero, return zero".
If, on the other hand, the parameter is not zero, we move the value into eax, and then move the value into [ecx + 0], which we know as the first data field in MyClass. We also see, from this code, that this first data field must be 4 bytes long (because we are using eax). After we move eax into [ecx + 0], we set eax to 1 and jump to the end of the function.
If we use the same MyClass defintion as in question 1, above, we can get the following code for our function, "SetValue1(int val)":
int MyClass::SetValue1(int val)
if(val == 0) return 0;
this->value1 = val;
Notice that since we are returning a 0 on failure, and a 1 on success, the function looks like it has a bool return value. However, the return value is 4 bytes wide (eax is used), but the size of a bool is implementation-specific, so we can't be sure. The bool is usually defined to have a size of 1 byte, but it is often stored the same way as an int.