I want use OF register to check for overflow.
I use this code :
auto GetFlags() {
unsigned long long flags;
int num = INT_MAX - INT_MIN; // Test
asm (
"pushfq\n\t"
"popq %0\n\t"
: "=r" (flags)
);
return (flags >> 11) & 1;
}
The variable num is used to make OF register 1. But use many times cout << GetFlags() << endl; only have 0.
I want to know the reason for the error, whether I need to write the subtraction into asm ? or the location of the obtained of register is wrong ?
translater:gcc 12.2.1
OS: Linux Arch 6.2.12(X64)
IDE: clion 2023.1.2(debug_x64)
Thanks.