AMD amd64 architecture User Manual

Page of 336
62
General-Purpose Programming
AMD64 Technology
24592—Rev. 3.15—November 2009
IRETD—Interrupt Return Doubleword
IRETQ—Interrupt Return Quadword
The INT instruction implements a software interrupt by calling an interrupt handler. The operand of
the INT instruction is an immediate byte value specifying an index in the interrupt descriptor table
(IDT), which contains addresses of interrupt handlers (see Section 3.7.10, “Interrupts and Exceptions,”
on page 86 
for further information on the IDT).
The 1-byte INTO instruction calls interrupt 4 (the overflow exception, #OF), if the overflow flag in
RFLAGS is set to 1, otherwise it does nothing. Signed arithmetic instructions can be followed by the
INTO instruction if the result of the arithmetic operation can potentially overflow. (The 1-byte INT 3
instruction is considered a system instruction and is therefore not described in this volume).
IRET, IRETD, and IRETQ perform a return from an interrupt handler. The mnemonic specifies the
operand size, which determines the format of the return addresses popped from the stack (IRET for 16-
bit operand size, IRETD for 32-bit operand size, and IRETQ for 64-bit operand size). However, some
assemblers can use the IRET mnemonic for all operand sizes. Actions performed by IRET are opposite
to actions performed by an interrupt or exception. In real and protected mode, IRET pops the rIP, CS,
and RFLAGS contents from the stack, and it pops SS:rSP if a privilege-level change occurs or if it
executes from 64-bit mode. In protected mode, the IRET instruction can also cause a task switch if the
nested task (NT) bit in the RFLAGS register is set. For details on using IRET to switch tasks, see “TaskManagement” in Volume 2.
3.3.12 Flags
The flags instructions read and write bits of the RFLAGS register that are visible to application
software. “Flags Register” on page 33 illustrates the RFLAGS register.
Push and Pop Flags
POPF—Pop to FLAGS Word
POPFD—Pop to EFLAGS Doubleword
POPFQ—Pop to RFLAGS Quadword
PUSHF—Push FLAGS Word onto Stack
PUSHFD—Push EFLAGS Doubleword onto Stack
PUSHFQ—Push RFLAGS Quadword onto Stack
The push and pop flags instructions copy data between the rFLAGS register and the stack. POPF and
PUSHF copy 16 bits of data between the stack and the FLAGS register (the low 16 bits of EFLAGS),
leaving the high 48 bits of RFLAGS unchanged. POPFD and PUSHFD copy 32 bits between the stack
and the RFLAGS register. POPFQ and PUSHFQ copy 64 bits between the stack and the RFLAGS
register. Only the bits illustrated in Figure 3-5 on page 34 are affected. Reserved bits and bits whose
writability is prevented by the current values of system flags, current privilege level (CPL), or current
operating mode, are unaffected by the POPF, POPFQ, and POPFD instructions.