User Guide
46 General-Purpose Programming
AMD64 Technology 24592—Rev. 3.15—November 2009
rBP register from the calling procedure. If the depth operand is greater than zero, the saved frame
pointer of the current procedure is pushed onto the stack (forming an array of depth frame pointers).
Finally, the saved value of the frame pointer is copied to the rBP register, and the rSP register is
decremented by the value of the first operand, allocating space for local variables used in the
procedure. See “Stack Operations” on page 44 for a parameter-passing instruction sequence using
PUSH that is equivalent to ENTER.
The LEAVE instruction removes local variables and the array of frame pointers, allocated by the
previous ENTER instruction, from the stack frame. This is accomplished by the following two steps:
first, the value of the frame pointer is copied from the rBP register to the rSP register. This releases the
space allocated by local variables and an array of frame pointers of procedures with smaller nesting
levels. Second, the rBP register is p opped from the stack, restoring the previous value of the frame
pointer (or simply the value of the rBP register, if the depth operand is zero). Thus, the LEAVE
instruction is equivalent to the following code:
mov rSP, rBP
pop rBP
3.3.3 Data Conversion
The data-conversion instructions perform various transformations of data, such as operand-size
doubling by sign extension, conversion of little-endian to big-endian format, extraction of sign masks,
searching a table, and support for operations with decimal numbers.
Sign Extension
• CBW—Convert Byte to Word
• CWDE—Convert Word to Doubleword
• CDQE—Convert Doubleword to Quadword
• CWD—Convert Word to Doubleword
• CDQ—Convert Doubleword to Quadword
• CQO—Convert Quadword to Octword
The CBW, CWDE, and CDQE instructions sign-extend the AL, AX, or EAX register to the upper half
of the AX, EAX, or RAX register, respectively. By doing so, these instructions create a double-sized
destination operand in rAX that has the same numerical value as the source operand. The CBW,
CWDE, and CDQE instructions have the same opcode, and the action taken depends on the effective
operand size.
The CWD, CDQ and CQO instructions sign-extend the AX, EAX, or RAX register to all bit positions
of the DX, EDX, or RDX register, respectively. By doing so, these instructions create a double-sized
destination operand in rDX:rAX that has the same numerical value as the source operand. The CWD,
CDQ, and CQO instructions have the same opcode, and the action taken depends on the effective
operand size.