Volume 3: General-Purpose and System Instructions - Stanford ...
Volume 3: General-Purpose and System Instructions - Stanford ... Volume 3: General-Purpose and System Instructions - Stanford ...
AMD64 Technology 24594 Rev. 3.10 February 2005BSWAPByte SwapReverses the byte order of the specified register. This action converts the contents ofthe register from little endian to big endian or vice versa. In a doubleword, bits 7–0 areexchanged with bits 31–24, and bits 15–8 are exchanged with bits 23–16. In aquadword, bits 7–0 are exchanged with bits 63–56, bits 15–8 with bits 55–48, bits 23–16with bits 47–40, and bits 31–24 with bits 39–32. A subsequent use of the BSWAPinstruction with the same operand restores the original value of the operand.The result of applying the BSWAP instruction to a 16-bit register is undefined. To swapthe bytes of a 16-bit register, use the XCHG instruction and specify the respective bytehalves of the 16-bit register as the two operands. For example, to swap the bytes of AX,use XCHG AL, AH.Mnemonic Opcode DescriptionBSWAP reg32 0F C8 +rd Reverse the byte order of reg32.BSWAP reg64 0F C8 +rq Reverse the byte order of reg64.Related InstructionsXCHGrFLAGS AffectedNoneExceptionsNone78 BSWAP
24594 Rev. 3.10 February 2005 AMD64 TechnologyBTBit TestCopies a bit, specified by a bit index in a register or 8-bit immediate value (secondoperand), from a bit string (first operand), also called the bit base, to the carry flag(CF) of the rFLAGS register.If the bit base operand is a register, the instruction uses the modulo 16, 32, or 64(depending on the operand size) of the bit index to select a bit in the register.If the bit base operand is a memory location, bit 0 of the byte at the specified addressis the bit base of the bit string. If the bit index is in a register, the instruction selects abit position relative to the bit base in the range –2 63 to +2 63 – 1 if the operand size is64, –2 31 to +2 31 – 1, if the operand size is 32, and –2 15 to +2 15 – 1 if the operand size is16. If the bit index is in an immediate value, the bit selected is that value modulo 16,32, or 64, depending on operand size.When the instruction attempts to copy a bit from memory, it accesses 2, 4, or 8 bytesstarting from the specified memory address for 16-bit, 32-bit, or 64-bit operand sizes,respectively, using the following formula:Effective Address + (NumBytes i * (BitOffset DIV NumBits i*8 ))When using this bit addressing mechanism, avoid referencing areas of memory closeto address space holes, such as references to memory-mapped I/O registers. Instead,use a MOV instruction to load a register from such an address and use a register formof the BT instruction to manipulate the data.Mnemonic Opcode DescriptionBT reg/mem16, reg16 0F A3 /r Copy the value of the selected bit to the carry flag.BT reg/mem32, reg32 0F A3 /r Copy the value of the selected bit to the carry flag.BT reg/mem64, reg64 0F A3 /r Copy the value of the selected bit to the carry flag.BT reg/mem16, imm8 0F BA /4 ib Copy the value of the selected bit to the carry flag.BT reg/mem32, imm8 0F BA /4 ib Copy the value of the selected bit to the carry flag.BT reg/mem64, imm8 0F BA /4 ib Copy the value of the selected bit to the carry flag.Related InstructionsBTC, BTR, BTSBT 79
- Page 58 and 59: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 60 and 61: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 62 and 63: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 64 and 65: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 66 and 67: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 68 and 69: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 70 and 71: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 72 and 73: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 74 and 75: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 76 and 77: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 78 and 79: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 80 and 81: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 82 and 83: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 84 and 85: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 86 and 87: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 88 and 89: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 90 and 91: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 92 and 93: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 94 and 95: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 96 and 97: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 98 and 99: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 100 and 101: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 102 and 103: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 104 and 105: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 106 and 107: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 110 and 111: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 112 and 113: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 114 and 115: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 116 and 117: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 118 and 119: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 120 and 121: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 122 and 123: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 124 and 125: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 126 and 127: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 128 and 129: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 130 and 131: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 132 and 133: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 134 and 135: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 136 and 137: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 138 and 139: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 140 and 141: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 142 and 143: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 144 and 145: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 146 and 147: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 148 and 149: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 150 and 151: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 152 and 153: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 154 and 155: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 156 and 157: AMD64 Technology 24594 Rev. 3.10 Fe
24594 Rev. 3.10 February 2005 AMD64 TechnologyBTBit TestCopies a bit, specified by a bit index in a register or 8-bit immediate value (secondoper<strong>and</strong>), from a bit string (first oper<strong>and</strong>), also called the bit base, to the carry flag(CF) of the rFLAGS register.If the bit base oper<strong>and</strong> is a register, the instruction uses the modulo 16, 32, or 64(depending on the oper<strong>and</strong> size) of the bit index to select a bit in the register.If the bit base oper<strong>and</strong> is a memory location, bit 0 of the byte at the specified addressis the bit base of the bit string. If the bit index is in a register, the instruction selects abit position relative to the bit base in the range –2 63 to +2 63 – 1 if the oper<strong>and</strong> size is64, –2 31 to +2 31 – 1, if the oper<strong>and</strong> size is 32, <strong>and</strong> –2 15 to +2 15 – 1 if the oper<strong>and</strong> size is16. If the bit index is in an immediate value, the bit selected is that value modulo 16,32, or 64, depending on oper<strong>and</strong> size.When the instruction attempts to copy a bit from memory, it accesses 2, 4, or 8 bytesstarting from the specified memory address for 16-bit, 32-bit, or 64-bit oper<strong>and</strong> sizes,respectively, using the following formula:Effective Address + (NumBytes i * (BitOffset DIV NumBits i*8 ))When using this bit addressing mechanism, avoid referencing areas of memory closeto address space holes, such as references to memory-mapped I/O registers. Instead,use a MOV instruction to load a register from such an address <strong>and</strong> use a register formof the BT instruction to manipulate the data.Mnemonic Opcode DescriptionBT reg/mem16, reg16 0F A3 /r Copy the value of the selected bit to the carry flag.BT reg/mem32, reg32 0F A3 /r Copy the value of the selected bit to the carry flag.BT reg/mem64, reg64 0F A3 /r Copy the value of the selected bit to the carry flag.BT reg/mem16, imm8 0F BA /4 ib Copy the value of the selected bit to the carry flag.BT reg/mem32, imm8 0F BA /4 ib Copy the value of the selected bit to the carry flag.BT reg/mem64, imm8 0F BA /4 ib Copy the value of the selected bit to the carry flag.Related <strong>Instructions</strong>BTC, BTR, BTSBT 79