1

I am using masm615 assembler and textpad as an editor. I am writing 32 bit assembly program. In the program I am trying to set zero flag as a result of mul instruction but it is not working. Can anyone tell me why the zero flag is clear while the result in eax register is zero. I am trying the following code

    include irvine32.inc
    .data
    .code
    main proc
    xor eax,eax
    call dumpregs
    xor ebx,ebx
    call dumpregs
    mov eax,2
    call dumpregs
    mov ebx,3
    call dumpregs
    sub eax,2
    call dumpregs
    mul ebx
    call dumpregs
    exit
    main endp
    end main
4

1 回答 1

2

在程序中,我试图将零标志设置为 mul 指令的结果

mul指令没有定义关于零标志是否或何时设置、清除或未修改的任何内容。请参阅英特尔® 64 和 IA-32 架构软件开发人员手册第 2 卷第 3-594 页,或其中的 HTML片段:

MUL—无符号乘法

...

受影响的标志

如果结果的上半部分为 0,则 OF 和 CF 标志设置为 0;否则,它们设置为1。SF、ZF、AF 和 PF 标志未定义。

如有疑问,请始终查看开发人员手册中的说明文档。并非所有指令都会影响人们可能期望的标志,或者人们期望的方式。

未定义意味着不同的 CPU 可能不同。例如,Skylake 在一些测试用例中设置 ZF=0,而不管输出或先前的值。有可能但不太可能存在 CPU 设置 ZF=1 的情况。当然,来自其他供应商(或仿真器)的其他 CPU 可以做任何他们想做的事情。

但与 C 的“未定义行为”不同,这只是一个未定义的;它仍然是 0 或 1。

于 2014-09-18T06:32:09.967 回答