I have the following disassembly:
[dest] = d5 cd e8 ca 68
movzx eax, [ebp+dest]
# value of edx at this point is: F7FBB898
movsx edx, al
# value of edx after this is: FFFFFFD5
# [ebp+var_E] stores 0
movzx eax, [ebp+var_E]
movsx eax, al
# eax = 0 here
add eax, edx
# eax becomes FFFFFFD5
cmp eax, 0D5h
jnz short loc_565564E6
I have given the explanation and flow for each instruction below:
What should be my initial value in [dest] so that after these operation, the final value in eax is 0xd5 and not 0xFFFFFFD5
You should use movzx
(Move with Zero-Extend) instead of movsx
(Move with Sign-Extension) if you want to extend the value with zeros without looking at its sign.
When you use movsx
to move 0xd5
to edx
, it will copy the lower to bytes into edx
and fill the remaining with the MSB of the copied value (0xd5
= 0b11010101
, the MSB is 1), which fills the 6 remaining bytes with 0xFFFFFF
. With movzx
, the remaining bytes are filled with 0x000000
regardless of the MSB.
User contributions licensed under CC BY-SA 3.0