How to read flag registers in x86 processor

Are there any assembly instructions that allow us to directly read or write the overflow flag to the 1680-bit Intel 80386 register? If not, what pseudo code should we use?

+4
source share
3 answers

To read only the overflow flag:

SETO AL ; AL now contains 1 if the overflow flag was set, and 0 if it wasn't 


To invert the overflow flag:

 PUSHF POP AX XOR AX,800h ; The overflow flag is in bit 11 PUSH AX POPF 
+7
source

To read flags in AX :

 pushf pop ax 

To write flags: if you need to set / clear certain bits, there are several commands, such as stc/clc (for the Carry flag), std/cld (for direction), etc .; but no bits are exposed that way. To write the entire register of flags, use

 push ax popf 
+1
source

Using

 Pushf // modify or read ax register Popf 
0
source

Source: https://habr.com/ru/post/1469007/


All Articles