HOME

TheInfoList



OR:

A trap flag permits operation of a processor in single- step mode. If such a flag is available,
debugger A debugger is a computer program used to test and debug other programs (the "target" programs). Common features of debuggers include the ability to run or halt the target program using breakpoints, step through code line by line, and display ...
s can use it to step through the execution of a
computer program A computer program is a sequence or set of instructions in a programming language for a computer to Execution (computing), execute. It is one component of software, which also includes software documentation, documentation and other intangibl ...
.


Single-step interrupt

When a system is instructed to single-step, it will execute one instruction and then stop. The contents of registers and memory locations can be examined; if they are correct, the system can be told to go on and execute the next instruction. The
Intel 8086 The 8086 (also called iAPX 86) is a 16-bit computing, 16-bit microprocessor chip designed by Intel between early 1976 and June 8, 1978, when it was released. The Intel 8088, released July 1, 1979, is a slightly modified chip with an external 8-b ...
trap flag and type-1
interrupt In digital computers, an interrupt (sometimes referred to as a trap) is a request for the processor to ''interrupt'' currently executing code (when permitted), so that the event can be processed in a timely manner. If the request is accepted ...
response make it quite easy to implement a single-step feature in an 8086-based system. If the trap flag is set, the 8086 will automatically do a type-1 interrupt after each instruction executes. When the 8086 does a type-1 interrupt, it pushes the flag register on the
stack Stack may refer to: Places * Stack Island, an island game reserve in Bass Strait, south-eastern Australia, in Tasmania’s Hunter Island Group * Blue Stack Mountains, in Co. Donegal, Ireland People * Stack (surname) (including a list of people ...
.


Setting

The
8086 The 8086 (also called iAPX 86) is a 16-bit microprocessor chip designed by Intel between early 1976 and June 8, 1978, when it was released. The Intel 8088, released July 1, 1979, is a slightly modified chip with an external 8-bit data bus (allo ...
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 p 100h ; Set TF flag popf ; Restore flag Register The Trap Flag is generally not used in this way, because programs are normally monitored from an Interrupt Service Routine (ISR). Execution of the program is generally continued by an IRET.Int3ISR: ; Stack: Ret, Flags pusha ; Stack: Ret, Flags, AX, CX, DX, BX, SP, BP, SI, DI push ds ; Stack: Ret, Flags, AX, CX, DX, BX, SP, BP, SI, DI, DS push es ; Stack: Ret, Flags, AX, CX, DX, BX, SP, BP, SI, DI, DS, ES ; ... the ISR code using only integers (otherwise you must also store floating point registers) mov bp, sp ; Stack: Ret, Flags, AX, CX, DX, BX, SP, BP, SI, DI, DS, ES mov bp, p+10 ; Stored SP or word p 100h ; Set TF flag in the stored FLAGS register pop es pop ds popa iret ; continue execution for one instruction, then calling the ISR again.


Resetting

To reset the trap flag, simply replace the OR instruction in the preceding sequence with the instruction: and word ptr p 0xFEFF The trap flag is reset when the
8086 The 8086 (also called iAPX 86) is a 16-bit microprocessor chip designed by Intel between early 1976 and June 8, 1978, when it was released. The Intel 8088, released July 1, 1979, is a slightly modified chip with an external 8-bit data bus (allo ...
does a type-1 interrupt, so the single-step mode will be disabled during the interrupt-service procedure.


References

{{Reflist Central processing unit Debugging