Volume 3 General-Purpose and System Instructions (794097), страница 19
Текст из файла (страница 19)
If the bit index is in a register, the instruction selects a bit position relative to the bit basein the range –263 to +263 – 1 if the operand size is 64, –231 to +231 – 1, if the operand size is 32, and–215 to +215 – 1 if the operand size is 16. If the bit index is in an immediate value, the bit selected isthat value modulo 16, 32, or 64, depending on the operand size.This instruction is useful for implementing semaphores in concurrent operating systems. Suchapplications should precede this instruction with the LOCK prefix. For details about the LOCK prefix,see “Lock Prefix” on page 8.MnemonicOpcodeDescriptionBTS reg/mem16, reg160F AB /rCopy the value of the selected bit to the carry flag, thenset the selected bit.BTS reg/mem32, reg320F AB /rCopy the value of the selected bit to the carry flag, thenset the selected bit.BTS reg/mem64, reg640F AB /rCopy the value of the selected bit to the carry flag, thenset the selected bit.BTS reg/mem16, imm80F BA /5 ibCopy the value of the selected bit to the carry flag, thenset the selected bit.BTS reg/mem32, imm80F BA /5 ibCopy the value of the selected bit to the carry flag, thenset the selected bit.BTS reg/mem64, imm80F BA /5 ibCopy the value of the selected bit to the carry flag, thenset the selected bit.Related InstructionsBT, BTC, BTR74BTSInstruction Reference24594—Rev.
3.13—July 2007AMD64 TechnologyrFLAGS AffectedIDVIPVIFACVMRFNTIOPLOFDFIFTFU2120191817161413–12111098SFZFAFPFCFUUUUM76420Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags areblank. Undefined flags are U.ExceptionsExceptionStack, #SSVirtualReal 8086 ProtectedCause of ExceptionXXXA memory address exceeded the stack segment limit or wasnon-canonical.XXXA memory address exceeded a data segment limit or was noncanonical.XThe destination operand was in a non-writable segment.XA null data segment was used to reference memory.General protection,#GPPage fault, #PFXXA page fault resulted from the execution of the instruction.Alignment check,#ACXXAn unaligned memory reference was performed whilealignment checking was enabled.Instruction ReferenceBTS75AMD64 Technology24594—Rev.
3.13—July 2007CALL (Near)Near Procedure CallPushes the offset of the next instruction onto the stack and branches to the target address, whichcontains the first instruction of the called procedure. The target operand can specify a register, amemory location, or a label. A procedure accessed by a near CALL is located in the same codesegment as the CALL instruction.If the CALL target is specified by a register or memory location, then a 16-, 32-, or 64-bit rIP is readfrom the operand, depending on the operand size.
A 16- or 32-bit rIP is zero-extended to 64 bits.If the CALL target is specified by a displacement, the signed displacement is added to the rIP (of thefollowing instruction), and the result is truncated to 16, 32, or 64 bits, depending on the operand size.The signed displacement is 16 or 32 bits, depending on the operand size.In all cases, the rIP of the instruction after the CALL is pushed on the stack, and the size of the stackpush (16, 32, or 64 bits) depends on the operand size of the CALL instruction.For near calls in 64-bit mode, the operand size defaults to 64 bits.
The E8 opcode results inRIP = RIP + 32-bit signed displacement and the FF /2 opcode results in RIP = 64-bit offset fromregister or memory. No prefix is available to encode a 32-bit operand size in 64-bit mode.At the end of the called procedure, RET is used to return control to the instruction following theoriginal CALL. When RET is executed, the rIP is popped off the stack, which returns control to theinstruction after the CALL.See CALL (Far) for information on far calls—calls to procedures located outside of the current codesegment. For details about control-flow instructions, see “Control Transfers” in Volume 1, and“Control-Transfer Privilege Checks” in Volume 2.MnemonicOpcodeDescriptionCALL rel16offE8 iwNear call with the target specified by a 16-bit relativedisplacement.CALL rel32offE8 idNear call with the target specified by a 32-bit relativedisplacement.CALL reg/mem16FF /2Near call with the target specified by reg/mem16.CALL reg/mem32FF /2Near call with the target specified by reg/mem32.
(Thereis no prefix for encoding this in 64-bit mode.)CALL reg/mem64FF /2Near call with the target specified by reg/mem64.For details about control-flow instructions, see “Control Transfers” in Volume 1, and “ControlTransfer Privilege Checks” in Volume 2.Related InstructionsCALL(Far), RET(Near), RET(Far)76CALL (Near)Instruction Reference24594—Rev. 3.13—July 2007AMD64 TechnologyrFLAGS AffectedNone.ExceptionsExceptionStack, #SSGeneral protection,#GPVirtualReal 8086 ProtectedCause of ExceptionXXXA memory address exceeded the stack segment limit or wasnon-canonical.XXXA memory address exceeded a data segment limit or was noncanonical.XXXThe target offset exceeded the code segment limit or was noncanonical.XA null data segment was used to reference memory.Alignment Check,#ACXXAn unaligned memory reference was performed whilealignment checking was enabled.Page Fault, #PFXXA page fault resulted from the execution of the instruction.Instruction ReferenceCALL (Near)77AMD64 Technology24594—Rev.
3.13—July 2007CALL (Far)Far Procedure CallPushes procedure linking information onto the stack and branches to the target address, which containsthe first instruction of the called procedure. The operand specifies a target selector and offset.The instruction can specify the target directly, by including the far pointer in the CALL (Far) opcodeitself, or indirectly, by referencing a far pointer in memory. In 64-bit mode, only indirect far calls areallowed, executing a direct far call (opcode 9A) generates an undefined opcode exception.
For bothdirect and indirect far calls, if the CALL (Far) operand-size is 16 bits, the instruction's operand is a 16bit selector followed by a 16-bit offset. If the operand-size is 32 or 64 bits, the operand is a 16-bitselector followed by a 32-bit offset.The target selector used by the instruction can be a code selector in all modes. Additionally, the targetselector can reference a call gate in protected mode, or a task gate or TSS selector in legacy protectedmode.•••Target is a code selector—The CS:rIP of the next instruction is pushed to the stack, using operandsize stack pushes. Then code is executed from the target CS:rIP. In this case, the target offset canonly be a 16- or 32-bit value, depending on operand-size, and is zero-extended to 64 bits.
No CPLchange is allowed.Target is a call gate—The call gate specifies the actual target code segment and offset. Call gatesallow calls to the same or more privileged code. If the target segment is at the same CPL as thecurrent code segment, the CS:rIP of the next instruction is pushed to the stack.If the CALL (Far) changes privilege level, then a stack-switch occurs, using an inner-level stackpointer from the TSS. The CS:rIP of the next instruction is pushed to the new stack.
If the mode islegacy mode and the param-count field in the call gate is non-zero, then up to 31 operands arecopied from the caller's stack to the new stack. Finally, the caller's SS:rSP is pushed to the newstack.When calling through a call gate, the stack pushes are 16-, 32-, or 64-bits, depending on the size ofthe call gate. The size of the target rIP is also 16, 32, or 64 bits, depending on the size of the callgate. If the target rIP is less than 64 bits, it is zero-extended to 64 bits. Long mode only allows 64bit call gates that must point to 64-bit code segments.Target is a task gate or a TSS—If the mode is legacy protected mode, then a task switch occurs.
See“Hardware Task-Management in Legacy Mode” in volume 2 for details about task switches.Hardware task switches are not supported in long mode.See CALL (Near) for information on near calls—calls to procedures located inside the current codesegment. For details about control-flow instructions, see “Control Transfers” in Volume 1, and“Control-Transfer Privilege Checks” in Volume 2.78CALL (Far)Instruction Reference24594—Rev. 3.13—July 2007MnemonicAMD64 TechnologyOpcodeDescriptionCALL FAR pntr16:169A cdFar call direct, with the target specified by a far pointercontained in the instruction. (Invalid in 64-bit mode.)CALL FAR pntr16:329A cpFar call direct, with the target specified by a far pointercontained in the instruction. (Invalid in 64-bit mode.)CALL FAR mem16:16FF /3Far call indirect, with the target specified by a far pointerin memory.CALL FAR mem16:32FF /3Far call indirect, with the target specified by a far pointerin memory.Action// See “Pseudocode Definitions” on page 41.CALLF_START:IF (REAL_MODE)CALLF_REAL_OR_VIRTUALELSIF (PROTECTED_MODE)CALLF_PROTECTEDELSE // (VIRTUAL_MODE)CALLF_REAL_OR_VIRTUALCALLF_REAL_OR_VIRTUAL:IF (OPCODE = callf [mem])// CALLF Indirect{temp_RIP = READ_MEM.z [mem]temp_CS = READ_MEM.w [mem+Z]}ELSE // (OPCODE = callf direct){temp_RIP = z-sized offset specified in the instructionzero-extended to 64 bitstemp_CS = selector specified in the instruction}PUSH.v old_CSPUSH.v next_RIPIF (temp_RIP>CS.limit)EXCEPTION [#GP(0)]CS.sel = temp_CSCS.base = temp_CS SHL 4RIP = temp_RIPEXITCALLF_PROTECTED:Instruction ReferenceCALL (Far)79AMD64 Technology24594—Rev.