Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly 何时使用溢出标志?_Assembly_X86_Flags_Integer Overflow_Eflags - Fatal编程技术网

Assembly 何时使用溢出标志?

Assembly 何时使用溢出标志?,assembly,x86,flags,integer-overflow,eflags,Assembly,X86,Flags,Integer Overflow,Eflags,我想我是来学习设置溢出标志时的用例的:当有符号算术中的有符号位发生变化时。例如,以下三种情况: # For example, with overflow: mov $0b00100000, %al # 32 add $0b01100000, %al # 96 # --------------------- # $0b10000000 # Notice how the signed bit is set so the answer is -128, n

我想我是来学习设置溢出标志时的用例的:当有符号算术中的有符号位发生变化时。例如,以下三种情况:

    # For example, with overflow:
    mov $0b00100000, %al # 32
    add $0b01100000, %al # 96
    # ---------------------
    #   $0b10000000  # Notice how the signed bit is set so the answer is -128, not +128

    # And with negative numbers (subtracting two negative numbers) where the sign =-bit is different
    # mov $-0b00100000, %al # 
    mov  $0b10000000, %al # -128
    add  $0b10000001, %al # -127
    # ---------------------
    #    $0b00000001  # +1 -- again the sign bit changes, so we have the overflow on

    # Doing the same thing but subtracting a positive number to get the overflow instead
    mov  $0b10000000, %al # -128
    sub  $0b00000100, %al # 4
    # ---------------------
    #    $0b01111100 # + 124 -- result is positive, so again we have overflow

但是,当使用
溢出
标志时,有些应用程序或用例是什么?根据我所掌握的最起码的asm知识,似乎总是使用
Z
ero和
S
ign标志进行比较,但是在什么用例中使用了
O
verflow标志?

每当您对有符号加法或减法是否溢出感兴趣时(也通过有符号比较进行隐式检查)。请注意,单独使用符号标志的频率低于与溢出标志一起使用的频率。例如,
JG
检查
ZF==0和&SF==OF
@Jester谢谢。请你详细说明一下,也许在回答中可以?例如,为什么它要检查
SF==OF
?因为正如您自己所描述的,如果发生溢出,SF就会反转。因此,要检查大于,您要么有一个没有溢出的正结果(
SF=OF=0
),要么有一个溢出的负结果(
SF=OF=1
)。@Jester这很有意义,感谢您的解释。类似的表显示了哪些指令可以修改此标志。基本上就是加、减和有符号乘法,他们用它来表示有符号算术的自然意义上的“溢出”。注
cmp
是减法的一个版本。按位操作倾向于无条件地清除它。