# An example of an overflow condition in a SUB instruction
#
# 和带符号整数加法的情况一样,如果执行带符号整数的减法,进位标志是没有用处的。
# 因为结果常常可能是负值。
# 替换的做法是,必须依靠溢出标志来判断到达了数据长度界限的情况。
#
.section .data
output:
.asciz "The result is %d\n"
.section .text
.globl main
main:
movl $-1590876934, %ebx
movl $1259230143, %eax
subl %eax, %ebx
jo over # 检测溢出标志
push %ebx
push $output
call printf
add $8, %esp
push $1
call exit
over:
push $0
push $output
call printf
add $8, %esp
push $0
call exit
# gcc -g -o 06 06-sub-overflow.s -m32
#
# The result is 0
#