MSDN, Article x64 Software Conventions / Register Usage . If the table does not explicitly indicate that the register "must be kept by the called object", then it is impossible to rely on its value, which was before the call to the function call.
Регистр статус Применение RAX Временный Регистр возвращаемого значения RCX Временный Первый целочисленный аргумент RDX Временный Второй целочисленный аргумент ... RDI Постоянный Должен сохраняться вызываемым объектом RSI Постоянный Должен сохраняться вызываемым объектом RBX Постоянный Должен сохраняться вызываемым объектом RBP Постоянный Может использоваться как указатель кадра. Должен сохраняться вызываемым объектом RSP Постоянный Указатель стека ...
For 32-bit and 16-bit architectures, there are slight differences, but in any case, the safety of the ecx ( cx ) ecx during the operation of the function is not guaranteed.
WriteConsoleAwrites to this register without saving it. See the calling convention that this function uses, and use a different register — mymedia