Are there any assembly instructions to let us directly read or write the overflow flag in Intel's 80386 16-bit Flags register ? If not, what pseudo code should we use?
Asked
Active
Viewed 6,056 times
4
-
4One can use pushf and popf to save/restore them using stack. (popfd, popfq restore the 32-bit and 64-bit extensions of the EFLAGS / RFLAGS respectively) – Aki Suihkonen Mar 13 '13 at 15:19
3 Answers
8
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
Michael
- 52,337
- 9
- 68
- 113
-
The OP is asking for 16-bit FLAGS; your code is 32-bit. -1 for not reading the question. – Seva Alekseyev Mar 13 '13 at 15:57
-
3That's a fairly minor detail to get hung up on considering that it should be obvious how to make the same code 16-bit. Edited the answer anyway. – Michael Mar 13 '13 at 16:07
-
3That obviously wasn't the case since the question title only mentions reading the flags. I simply overlooked one detail when writing my initial answer, which I honestly don't think made the example "not useful". – Michael Mar 13 '13 at 16:23
1
To read the flags into AX
:
pushf
pop ax
To write the flags: if you need to set/clear specific bits, there are some commands like stc/clc
(for Carry flag), std/cld
(for Direction) and so forth; but not bits are exposed this way. To write the whole flags register, use
push ax
popf
Seva Alekseyev
- 55,897
- 22
- 151
- 252