Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
X86 assembly language
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Program flow== The x86 assembly has an unconditional jump operation, [[JMP (x86 instruction)|<code>jmp</code>]], which can take an immediate address, a register or an indirect address as a parameter (note that most RISC processors only support a link register or short immediate displacement for jumping). Also supported are several conditional jumps, including <code>jz</code> (jump on zero), <code>jnz</code> (jump on non-zero), <code>jg</code> (jump on greater than, signed), <code>jl</code> (jump on less than, signed), <code>ja</code> (jump on above/greater than, unsigned), <code>jb</code> (jump on below/less than, unsigned). These conditional operations are based on the state of specific bits in the [[FLAGS register (computing)|(E)FLAGS]] register. Many arithmetic and logic operations set, clear or complement these flags depending on their result. The comparison <code>cmp</code> (compare) and [[TEST (x86 instruction)|<code>test</code>]] instructions set the flags as if they had performed a subtraction or a bitwise AND operation, respectively, without altering the values of the operands. There are also instructions such as <code>clc</code> (clear carry flag) and <code>cmc</code> (complement carry flag) which work on the flags directly. Floating point comparisons are performed via <code>fcom</code> or <code>ficom</code> instructions which eventually have to be converted to integer flags. Each jump operation has three different forms, depending on the size of the operand. A ''short'' jump uses an 8-bit signed operand, which is a relative offset from the current instruction. A ''near'' jump is similar to a short jump but uses a 16-bit signed operand (in real or protected mode) or a 32-bit signed operand (in 32-bit protected mode only). A ''far'' jump is one that uses the full segment base:offset value as an absolute address. There are also indirect and indexed forms of each of these. In addition to the simple jump operations, there are the <code>call</code> (call a subroutine) and <code>ret</code> (return from subroutine) instructions. Before transferring control to the subroutine, <code>call</code> pushes the segment offset address of the instruction following the <code>call</code> onto the stack; <code>ret</code> pops this value off the stack, and jumps to it, effectively returning the flow of control to that part of the program. In the case of a <code>far call</code>, the segment base is pushed following the offset; <code>far ret</code> pops the offset and then the segment base to return. There are also two similar instructions, [[INT (x86 instruction)|<code>int</code>]] ([[interrupt]]), which saves the current [[FLAGS register (computing)|(E)FLAGS]] register value on the stack, then performs a <code>far call</code>, except that instead of an address, it uses an ''interrupt vector'', an index into a table of interrupt handler addresses. Typically, the interrupt handler saves all other CPU registers it uses, unless they are used to return the result of an operation to the calling program (in software called interrupts). The matching return from interrupt instruction is <code>iret</code>, which restores the flags after returning. ''Soft Interrupts'' of the type described above are used by some operating systems for [[system call]]s, and can also be used in debugging hard interrupt handlers. ''Hard interrupts'' are triggered by external hardware events, and must preserve all register values as the state of the currently executing program is unknown. In Protected Mode, interrupts may be set up by the OS to trigger a task switch, which will automatically save all registers of the active task.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)