Volume 2B Instruction Set Reference N-Z (794102), страница 36
Текст из файла (страница 36)
2B 4-253INSTRUCTION SET REFERENCE, N-ZOpcodeInstruction64-BitModeCompat/Leg ModeDescriptionF3 ADREP LODS EAXValidValidLoad (E)CX doublewords fromDS:[(E)SI] to EAX.F3 REX.W ADREP LODS RAXValidN.E.Load RCX quadwords from [RSI]to RAX.F3 AAREP STOS m8ValidValidFill (E)CX bytes at ES:[(E)DI] withAL.F3 REX.W AAREP STOS m8ValidN.E.Fill RCX bytes at [RDI] with AL.F3 ABREP STOS m16ValidValidFill (E)CX words at ES:[(E)DI]with AX.F3 ABREP STOS m32ValidValidFill (E)CX doublewords atES:[(E)DI] with EAX.F3 REX.W ABREP STOS m64ValidN.E.Fill RCX quadwords at [RDI] withRAX.F3 A6REPE CMPS m8, m8 ValidValidFind nonmatching bytes inES:[(E)DI] and DS:[(E)SI].F3 REX.W A6REPE CMPS m8, m8 ValidN.E.Find non-matching bytes in[RDI] and [RSI].F3 A7REPE CMPS m16,m16ValidValidFind nonmatching words inES:[(E)DI] and DS:[(E)SI].F3 A7REPE CMPS m32,m32ValidValidFind nonmatching doublewordsin ES:[(E)DI] and DS:[(E)SI].F3 REX.W A7REPE CMPS m64,m64ValidN.E.Find non-matching quadwordsin [RDI] and [RSI].F3 AEREPE SCAS m8ValidValidFind non-AL byte starting atES:[(E)DI].F3 REX.W AEREPE SCAS m8ValidN.E.Find non-AL byte starting at[RDI].F3 AFREPE SCAS m16ValidValidFind non-AX word starting atES:[(E)DI].F3 AFREPE SCAS m32ValidValidFind non-EAX doublewordstarting at ES:[(E)DI].F3 REX.W AFREPE SCAS m64ValidN.E.Find non-RAX quadwordstarting at [RDI].F2 A6REPNE CMPS m8,m8ValidValidFind matching bytes in ES:[(E)DI]and DS:[(E)SI].F2 REX.W A6REPNE CMPS m8,m8ValidN.E.Find matching bytes in [RDI] and[RSI].4-254 Vol.
2BREP/REPE/REPZ/REPNE/REPNZ—Repeat String Operation PrefixINSTRUCTION SET REFERENCE, N-ZOpcodeInstruction64-BitModeCompat/Leg ModeDescriptionF2 A7REPNE CMPS m16,m16ValidValidFind matching words inES:[(E)DI] and DS:[(E)SI].F2 A7REPNE CMPS m32,m32ValidValidFind matching doublewords inES:[(E)DI] and DS:[(E)SI].F2 REX.W A7REPNE CMPS m64,m64ValidN.E.Find matching doublewords in[RDI] and [RSI].F2 AEREPNE SCAS m8ValidValidFind AL, starting at ES:[(E)DI].F2 REX.W AEREPNE SCAS m8ValidN.E.Find AL, starting at [RDI].F2 AFREPNE SCAS m16ValidValidFind AX, starting at ES:[(E)DI].F2 AFREPNE SCAS m32ValidValidFind EAX, starting at ES:[(E)DI].F2 REX.W AFREPNE SCAS m64ValidN.E.Find RAX, starting at [RDI].NOTES:* In 64-bit mode, r/m8 can not be encoded to access the following byte registers if a REX prefix isused: AH, BH, CH, DH.DescriptionRepeats a string instruction the number of times specified in the count register oruntil the indicated condition of the ZF flag is no longer met.
The REP (repeat), REPE(repeat while equal), REPNE (repeat while not equal), REPZ (repeat while zero), andREPNZ (repeat while not zero) mnemonics are prefixes that can be added to one ofthe string instructions. The REP prefix can be added to the INS, OUTS, MOVS, LODS,and STOS instructions, and the REPE, REPNE, REPZ, and REPNZ prefixes can beadded to the CMPS and SCAS instructions. (The REPZ and REPNZ prefixes are synonymous forms of the REPE and REPNE prefixes, respectively.) The behavior of the REPprefix is undefined when used with non-string instructions.The REP prefixes apply only to one string instruction at a time.
To repeat a block ofinstructions, use the LOOP instruction or another looping construct. All of theserepeat prefixes cause the associated instruction to be repeated until the count inregister is decremented to 0. See Table 4-3.REP/REPE/REPZ/REPNE/REPNZ—Repeat String Operation PrefixVol. 2B 4-255INSTRUCTION SET REFERENCE, N-ZTable 4-3. Repeat PrefixesRepeat PrefixTermination Condition 1*Termination Condition 2REPRCX or (E)CX = 0NoneREPE/REPZRCX or (E)CX = 0ZF = 0REPNE/REPNZRCX or (E)CX = 0ZF = 1NOTES:* Count register is CX, ECX or RCX by default, depending on attributes of the operating modes.
In64-bit mode, if default operation size is 32 bits, the count register becomes RCX when a REX.Wprefix is used.The REPE, REPNE, REPZ, and REPNZ prefixes also check the state of the ZF flag aftereach iteration and terminate the repeat loop if the ZF flag is not in the specified state.When both termination conditions are tested, the cause of a repeat termination canbe determined either by testing the count register with a JECXZ instruction or bytesting the ZF flag (with a JZ, JNZ, or JNE instruction).When the REPE/REPZ and REPNE/REPNZ prefixes are used, the ZF flag does notrequire initialization because both the CMPS and SCAS instructions affect the ZF flagaccording to the results of the comparisons they make.A repeating string operation can be suspended by an exception or interrupt.
Whenthis happens, the state of the registers is preserved to allow the string operation tobe resumed upon a return from the exception or interrupt handler. The source anddestination registers point to the next string elements to be operated on, the EIPregister points to the string instruction, and the ECX register has the value it heldfollowing the last successful iteration of the instruction. This mechanism allows longstring operations to proceed without affecting the interrupt response time of thesystem.When a fault occurs during the execution of a CMPS or SCAS instruction that isprefixed with REPE or REPNE, the EFLAGS value is restored to the state prior to theexecution of the instruction. Since the SCAS and CMPS instructions do not useEFLAGS as an input, the processor can resume the instruction after the page faulthandler.Use the REP INS and REP OUTS instructions with caution.
Not all I/O ports can handlethe rate at which these instructions execute. Note that a REP STOS instruction is thefastest way to initialize a large block of memory.In 64-bit mode, default operation size is 32 bits. The default count register is RCX forREP INS and REP OUTS; it is ECX for other instructions. REX.W does not promoteoperation to 64-bit for REP INS and REP OUTS. However, using a REX prefix in theform of REX.W does promote operation to 64-bit operands for otherREP/REPNE/REPZ/REPNZ instructions. See the summary chart at the beginning ofthis section for encoding data and limits.4-256 Vol. 2BREP/REPE/REPZ/REPNE/REPNZ—Repeat String Operation PrefixINSTRUCTION SET REFERENCE, N-ZOperationIF AddressSize = 16THENUse CX for CountReg;ELSE IF AddressSize = 64 and REX.W usedTHEN Use RCX for CountReg; FI;ELSEUse ECX for CountReg;FI;WHILE CountReg ≠ 0DOService pending interrupts (if any);Execute associated string instruction;CountReg ← (CountReg – 1);IF CountReg = 0THEN exit WHILE loop; FI;IF (Repeat prefix is REPZ or REPE) and (ZF = 0)or (Repeat prefix is REPNZ or REPNE) and (ZF = 1)THEN exit WHILE loop; FI;OD;Flags AffectedNone; however, the CMPS and SCAS instructions do set the status flags in theEFLAGS register.Exceptions (All Operating Modes)Exceptions may be generated by an instruction associated with the prefix.64-Bit Mode Exceptions#GP(0)If the memory address is in a non-canonical form.REP/REPE/REPZ/REPNE/REPNZ—Repeat String Operation PrefixVol.
2B 4-257INSTRUCTION SET REFERENCE, N-ZRET—Return from ProcedureOpcodeInstruction64-BitModeCompat/Leg ModeDescriptionC3RETValidValidNear return to calling procedure.CBRETValidValidFar return to calling procedure.C2 iwRET imm16ValidValidNear return to calling procedure and popimm16 bytes from stack.CA iwRET imm16ValidValidFar return to calling procedure and popimm16 bytes from stack.DescriptionTransfers program control to a return address located on the top of the stack.
Theaddress is usually placed on the stack by a CALL instruction, and the return is madeto the instruction that follows the CALL instruction.The optional source operand specifies the number of stack bytes to be released afterthe return address is popped; the default is none. This operand can be used torelease parameters from the stack that were passed to the called procedure and areno longer needed. It must be used when the CALL instruction used to switch to a newprocedure uses a call gate with a non-zero word count to access the new procedure.Here, the source operand for the RET instruction must specify the same number ofbytes as is specified in the word count field of the call gate.The RET instruction can be used to execute three different types of returns:•Near return — A return to a calling procedure within the current code segment(the segment currently pointed to by the CS register), sometimes referred to asan intrasegment return.•Far return — A return to a calling procedure located in a different segment thanthe current code segment, sometimes referred to as an intersegment return.•Inter-privilege-level far return — A far return to a different privilege levelthan that of the currently executing program or procedure.The inter-privilege-level return type can only be executed in protected mode.
See thesection titled “Calling Procedures Using Call and RET” in Chapter 6 of the Intel® 64and IA-32 Architectures Software Developer’s Manual, Volume 1, for detailed information on near, far, and inter-privilege-level returns.When executing a near return, the processor pops the return instruction pointer(offset) from the top of the stack into the EIP register and begins program executionat the new instruction pointer. The CS register is unchanged.When executing a far return, the processor pops the return instruction pointer fromthe top of the stack into the EIP register, then pops the segment selector from the topof the stack into the CS register.
The processor then begins program execution in thenew code segment at the new instruction pointer.4-258 Vol. 2BRET—Return from ProcedureINSTRUCTION SET REFERENCE, N-ZThe mechanics of an inter-privilege-level far return are similar to an intersegmentreturn, except that the processor examines the privilege levels and access rights ofthe code and stack segments being returned to determine if the control transfer isallowed to be made.
The DS, ES, FS, and GS segment registers are cleared by theRET instruction during an inter-privilege-level return if they refer to segments thatare not allowed to be accessed at the new privilege level. Since a stack switch alsooccurs on an inter-privilege level return, the ESP and SS registers are loaded fromthe stack.If parameters are passed to the called procedure during an inter-privilege level call,the optional source operand must be used with the RET instruction to release theparameters on the return.