Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assembly instruction for setting, clearing OF & TF flags

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?

like image 241
mohammad mahed Avatar asked Nov 17 '12 08:11

mohammad mahed


People also ask

How do you clear a flag in assembly?

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.

What is CLC in assembly language?

Clear Carry Flag (clc)

What is assembly instruction?

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.

What does XOR do in assembly?

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.


1 Answers

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.

like image 78
John Dvorak Avatar answered Sep 17 '22 22:09

John Dvorak