ia-32_volume1_basic-arch

Exchange instruction swaps the contents of two

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for more information on atomic operations.) 7-6 Vol. 1 PROGRAMMING WITH GENERAL-PURPOSE INSTRUCTIONS The CMPXCHG8B instruction also requires three operands: a 64-bit value in EDX:EAX, a 64-bit value in ECX:EBX, and a destination operand in memory. The instruction compares the 64-bit value in the EDX:EAX registers with the destination operand. If they are equal, the 64-bit value in the ECX:EBX register is stored in the destination operand. If the EDX:EAX register and the destination are not equal, the destination is loaded in the EDX:EAX register. The CMPXCHG8B instruction can be combined with the LOCK prefix to perform the operation atomically. 7.3.1.3 Exchange Instructions in 64-Bit Mode The CMPXCHG16B instruction is available in 64-bit mode only. It is an extension of the functionality provided by CMPXCHG8B that operates on 128-bits of data. 7.3.1.4 Stack Manipulation Instructions The PUSH, POP, PUSHA (push all registers), and POPA (pop all registers) instructions move data to and from the stack. The PUSH instruction decrements the stack pointer (contained in the ESP register), then copies the source operand to the top of stack (see Figure 7-1). It operates on memory operands, immediate operands, and register operands (including segment registers). The PUSH instruction is commonly used to place parameters on the stack before calling a procedure. It can also be used to reserve space on the stack for temporary variables. Stack Before Pushing Doubleword Stack Growth n n-4 n-8 31 0 ESP After Pushing Doubleword 31 Doubleword Value 0 ESP Figure 7-1. Operation of the PUSH Instruction The PUSHA instruction saves the contents of the eight general-purpose registers on the stack (see Figure 7-2). This instruction simplifies procedure calls by reducing the number of instructions required to save the contents of the general-purpose registers. The registers are pushed on the stack in the following order: EAX, ECX, EDX, EBX, the initial value of ESP before EAX was pushed, EBP, ESI, and EDI. Vol. 1 7-7 PROGRAMMING WITH GENERAL-PURPOSE INSTRUCTIONS Stack Stack Growth n n-4 n-8 n - 12 n - 16 n - 20 n - 24 n - 28 n - 32 n - 36 Before Pushing Registers 31 0 After Pushing Registers 31 0 ESP EAX ECX EDX EBX Old ESP EBP ESI EDI ESP Figure 7-2. Operation of the PUSHA Instruction The POP instruction copies the word or doubleword at the current top of stack (indicated by the ESP register) to the location specified with the destination operand. It then increments the ESP register to point to the new top of stack (see Figure 7-3). The destination operand may specify a general-purpose register, a segment register, or a memory location. Stack Before Popping Doubleword Stack Growth n n-4 n-8 31 0 After Popping Doubleword 31 0 ESP Doubleword Value ESP Figure 7-3. Operation of the POP Instruction The POPA instruction reverses the effect of the PUSHA instruction. It pops the top eight words or doublewords from the top of the stack into the general-purpose registers, except for th...
View Full Document

This note was uploaded on 10/01/2013 for the course CPE 103 taught by Professor Watlins during the Winter '11 term at Mississippi State.

Ask a homework question - tutors are online