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?
The best way to clear the carry flag is to use the CLC instruction; and the best way to set the carry flag is to use the STC instruction.
Clear Carry Flag (clc)
An assembler instruction is a request to the assembler to do certain operations during the assembly of a source module; for example, defining data constants, reserving storage areas, and defining the end of the source module.
The XOR instruction performs a bit wise Exclusive OR operation between corresponding bits in the two operands and places the result in the first operand. reg, mem, and immed can be 8, 16, or 32 bits. The XOR instruction can be used to reverse selected bits in an operand while preserving the remaining bits.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With