在 CodeView 中单步执行时,EBX 的高位被清零

Upper bits of EBX are zeroed out when single-stepping in CodeView

我有以下用 MASM 为 i386 处理器编写的简单程序:

        TITLE   BLA
        .MODEL  SMALL
        .386
        .STACK
        .DATA
        .CODE
MAIN    PROC    FAR
        .STARTUP
        MOV     EBX,0FFFFFFFFH; (1)
        MOV     EAX,0EEEEEEEEH; (2)
       .EXIT
MAIN    ENDP
END

我对 EBX 寄存器的行为感到困惑。在 (1) 指令之后,EBX 设置为 1-s:

执行(2)指令不仅将值加载到EAX中,还将EBX的上半部分清零:

为什么会发生这种情况?

根据 Microsoft 的说法,这是 Codeview 中的一个已知错误。请参阅知识库文章 Q87548

SYMPTOMS

When single-stepping or tracing through code in Microsoft CodeView versions 4.0, 4.01, and 4.05, the lower half of the 32-bit registers (eax, ebx, edi, etc.) is always preserved, but the upper half may be corrupted. Other 386- specific registers, such as the gs and fs registers, may also be corrupted. This problem also occurs when animating. This problem does not occur if the instructions are not executed one at a time.

STATUS

Microsoft has confirmed this to be a problem in CodeView version 4.0, 4.01, and 4.05. This problem was corrected in CodeView version 4.1.

根据这篇文章,解决方法是获取 Codeview 4.1 或更高版本。