I have an unknown C ++ code that was compiled in Release build, so it is optimized. What I'm struggling with is:
xor al, al add esp, 8 cmp byte ptr [ebp+userinput], 31h movzx eax, al
This is my understanding:
xor al, al ; set eax to 0x??????00 (clear last byte) add esp, 8 ; for some unclear reason, set the stack pointer higher cmp byte ptr [ebp+userinput], 31h ; set zero flag if user input was "1" movzx eax, al ; set eax to AL and extend with zeros, so eax = 0x000000??
I don't need lines 2 and 3. They can be in this order for pipelining reasons, and IMHO has nothing to do with EAX.
However, I don't understand why I first cleared AL, but just cleared the rest of EAX later. The result will be IMHO always EAX = 0 , so it could also be
xor eax, eax
instead of this. What is the advantage or “optimization” of this part of the code?
Some background information:
I will get the source code later. This is a small C ++ console demo, perhaps only 20 lines of code, so there’s nothing that I would call "complex" code. The IDA shows one cycle in this program, but not around this part. Stud_PE's signature scan did not find anything, but most likely it is a Visual Studio 2013 or 2015 compiler.