Assembly instruction for setting, clearing OF & TF flags
Asked Answered
P

1

5

Are there any assembly instructions to let us directly "set" or "clear" the "OF" and "TF" flags in Intel's 8086 16-bit Flags register ? If not, what pseudo code should we use?

Puree answered 17/11, 2012 at 8:36 Comment(3)
Have you read the Intel Manuals before asking this question?Youlandayoulton
en.wikipedia.org/wiki/Trap_flagRiven
@DCoder have you ever found a pseudo code for such thing in Intel Manuals before posting comment ?!Puree
R
8

http://en.wikipedia.org/wiki/Trap_flag

The 8086 has no instruction to directly set or reset the trap flag. These operations are done by pushing the flag register on the stack, changing the trap flag bit to what the programmer wants it to be, and then popping the flag register back off the stack. The instructions to set the trap flag are:

PUSHF ; Push flags on stack
MOV BP,SP  ; Copy SP to BP for use as index
OR WORD PTR[BP+0],0100H ; Set TF flag
POPF  ; Restore flag Register

To reset the trap flag, simply replace the OR instruction in the preceding sequence with the instruction:

AND WORD PTR[BP+0],0FEFFH

To set and clear the overflow flag, you can do the same, replacing 0100H with 0800H and 0FEFFh with 0F7FFh.

Be sure to know what TF does before you set it. It's a trap.

Riven answered 17/11, 2012 at 8:53 Comment(2)
What is the reason for doing mov bp,sp and using bp register when you can just do or word [sp], 0100h using solely sp register?Chamomile
because 8086 is running in 16-bit real mode, there is no such way to make word [sp] as the only possible base registers in a memory operand are BX, BP, SI and DI.Overseas

© 2022 - 2024 — McMap. All rights reserved.