For many years, ntohs (32-bit version) had a return value that was zero extended into the high 16 bits (word). However, after a recent update of Windows 10, it sometimes returns garbage in the upper word.
For example, passing argument 0xF00D to
call ntohs
the return values are
- EAX = 00F00DF0 (32-bit code)
- RAX = 0000000000000DF0 (64-bit code)
The fix in MASM code is to zero extend the return register using movzx (identical to MSVC)
call ntohs
movzx eax, ax
Question
Is it correct that any Windows API with a return value that's documented as less than native register width, there's no guarantee of the upper bits being zeroed out i.e., the return value in RAX = 0000000000000DF0 (64-bit) was most likely coincidental?