X86 Assembly/Other Instructions

From Wikibooks, the open-content textbooks collection

Jump to: navigation, search

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.

[edit] Flags instructions

[edit] Interrupt Flag

sti

Sets the interrupt flag. Processor can accept interrupts from peripheral hardware. This flag should be kept set under normal execution.

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

std

Sets the direction flag. Normally, when using string instructions the data pointer gets incremented with each iteration. When the direction flag is set, the data pointer is decremented instead.

cld

Clears the direction flag.

[edit] Carry Flag

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.

sysexit

This instruction causes the processor to leave protected system mode, and enter user mode.