X86 Assembly/Other Instructions
Contents |
[edit] Stack Instructions
push arg
This instruction decrements the stack pointer and loads the data specified as the argument into the location pointed to by the stack pointer.
pop arg
This instruction loads the data stored in the location pointed to by the stack pointer into the argument specified and then increments the stack pointer. For example:
mov eax, 5 mov ebx, 6 |
|
push eax |
The stack is now: [5] |
push ebx |
The stack is now: [6] [5] |
pop eax |
The topmost item (which is 6) is now stored in eax. The stack is now: [5] |
pop ebx |
ebx is now equal to 5. The stack is now empty. |
pushf
This instruction decrements the stack pointer and then loads the location pointed to by the stack pointer with the contents of the flag register.
popf
This intruction loads the flag register with the contents of the memory location pointed to by the stack pointer and then increments the contents of the stack pointer.
pusha
This instruction pushes all the general purpose registers onto the stack in the following order: EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI. The value of ESP pushed is the value before the instruction is executed. It is useful for saving state before an operation that could potential change these registers.
popa
This instruction pops all the general purpose registers off the stack in the reverse order of PUSHA. That is, EDI, ESI, EBP, ESP, EBX, EDX, ECX, EAX. Used to restore state after a call to PUSHA.
[edit] Flags instructions
While the flags register is used to report on results of executed instructions (overflow, carry, etc.), it also contains flags that affect the operation of the processor. These flags are set and cleared with special instructions.
[edit] Interrupt Flag
The IF flag tells a processor if it should accept hardware interrupts. It should be kept set under normal execution. In fact, in protected mode, neither of these instructions can be executed by user-level programs.
sti
Sets the interrupt flag. If set, the processor can accept interrupts from peripheral hardware.
cli
Clears the interrupt flag. Hardware interrupts cannot interrupt execution. Programs can still generate interrupts, called software interrupts, and change the flow of execution. Non-maskable interrupts (NMI) cannot be blocked using this instruction.
[edit] Direction Flag
The DF flag tells the processor which way to read data when when using string instructions. That is, whether to decrement or increment the esi and edi registers after a movs instruction.
std
Sets the direction flag. Registers will decrement, reading backwards.
cld
Clears the direction flag. Registers will increment, reading forwards.
[edit] Carry Flag
The CF flag is often modified after arithmetic instructions, but it can be set or cleared manually as well.
stc
Sets the carry flag.
clc
Clears the carry flag.
cmc
Complements (inverts) the carry flag.
[edit] Other
sahf
Stores the content of AH register into the lower byte of the flag register.
lahf
Loads the AH register with the contents of the lower byte of the flag register.
[edit] I/O Instructions
| in src, dest | GAS Syntax |
| in dest, src | Intel syntax |
The IN instruction almost always has the operands AX and DX (or EAX and EDX) associated with it. DX (src) frequently holds the port address to read, and AX (dest) receives the data from the port. In Protected Mode operating systems, the IN instruction is frequently locked, and normal users can't use it in their programs.
| out src, dest | GAS Syntax |
| out dest, src | Intel syntax |
The OUT instruction is very similar to the IN instruction. OUT outputs data from a given register (src) to a given output port (dest). In protected mode, the OUT instruction is frequently locked so normal users can't use it.
[edit] System Instructions
These instructions were added with the Pentium II.
sysenter
This instruction causes the processor to enter protected system mode (supervisor mode or "kernel mode").
sysexit
This instruction causes the processor to leave protected system mode, and enter user mode.
This page may need to be