⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 s03_05.htm

📁 Programmer s Reference Manual is an improtant book on Intel processor architecture and programming.
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><HTML><HEAD><TITLE>80386 Programmer's Reference Manual -- Section 3.5</TITLE></HEAD><BODY><B>up:</B> <A HREF="c03.htm">Chapter 3 -- Applications Instruction Set</A><BR><B>prev:</B> <A HREF="s03_04.htm">3.4  Logical Instructions</A><BR><B>next:</B> <A HREF="s03_06.htm">3.6  String and Character Translation Instructions</A><P><HR><P><H1>3.5  Control Transfer Instructions</H1>The 80386 provides both conditional and unconditional control transferinstructions to direct the flow of execution. Conditional control transfersdepend on the results of operations that affect the flag register.Unconditional control transfers are always executed.<H2>3.5.1  Unconditional Transfer Instructions</H2><A HREF="JMP.htm">JMP</A>, <A HREF="CALL.htm">CALL</A>, <A HREF="RET.htm">RET</A>, <A HREF="INT.htm">INT</A> and <A HREF="IRET.htm">IRET</A> instructions transfer control from one codesegment location to another. These locations can be within the same codesegment (near control transfers) or in different code segments (far controltransfers). The variants of these instructions that transfer control toother segments are discussed in a later section of this chapter. If themodel of memory organization used in a particular 80386 application doesnot make segments visible to applications programmers, intersegment controltransfers will not be used.<H3>3.5.1.1  Jump Instruction</H3><A HREF="JMP.htm">JMP</A> (Jump) unconditionally transfers control to the target location. <A HREF="JMP.htm">JMP</A> isa one-way transfer of execution; it does not save a return address on thestack.<P>The <A HREF="JMP.htm">JMP</A> instruction always performs the same basic function of transferringcontrol from the current location to a new location. Its implementationvaries depending on whether the address is specified directly within theinstruction or indirectly through a register or memory.<P>A direct <A HREF="JMP.htm">JMP</A> instruction includes the destination address as part of theinstruction. An indirect <A HREF="JMP.htm">JMP</A> instruction obtains the destination addressindirectly through a register or a pointer variable.<P>Direct near <A HREF="JMP.htm">JMP</A>. A direct <A HREF="JMP.htm">JMP</A> uses a relative displacement value containedin the instruction. The displacement is signed and the size of thedisplacement may be a byte, word, or doubleword. The processor forms aneffective address by adding this relative displacement to the addresscontained in EIP. When the additions have been performed, EIP refers to thenext instruction to be executed.<P>Indirect near <A HREF="JMP.htm">JMP</A>. Indirect <A HREF="JMP.htm">JMP</A> instructions specify an absolute address inone of several ways:<OL><LI> The program can <A HREF="JMP.htm">JMP</A> to a location specified by a general register(any of EAX, EDX, ECX, EBX, EBP, ESI, or EDI). The processor movesthis 32-bit value into EIP and resumes execution.<LI> The processor can obtain the destination address from a memoryoperand specified in the instruction.<LI> A register can modify the address of the memory pointer to select adestination address.</OL><H3>3.5.1.2  Call Instruction</H3><A HREF="CALL.htm">CALL</A> (Call Procedure) activates an out-of-line procedure, saving on thestack the address of the instruction following the <A HREF="CALL.htm">CALL</A> for later use by a<A HREF="RET.htm">RET</A> (Return) instruction. <A HREF="CALL.htm">CALL</A> places the current value of EIP on the stack.The <A HREF="RET.htm">RET</A> instruction in the called procedure uses this address to transfercontrol back to the calling program.<P><A HREF="CALL.htm">CALL</A> instructions, like <A HREF="JMP.htm">JMP</A> instructions have relative, direct, andindirect versions.<P>Indirect <A HREF="CALL.htm">CALL</A> instructions specify an absolute address in one of these ways:<OL><LI> The program can <A HREF="CALL.htm">CALL</A> a location specified by a general register (anyof EAX, EDX, ECX, EBX, EBP, ESI, or EDI). The processor moves this32-bit value into EIP.<LI> The processor can obtain the destination address from a memoryoperand specified in the instruction.</OL><H3>3.5.1.3  Return and Return-From-Interrupt Instruction</H3><A HREF="RET.htm">RET</A> (Return From Procedure) terminates the execution of a procedure andtransfers control through a back-link on the stack to the program thatoriginally invoked the procedure. <A HREF="RET.htm">RET</A> restores the value of EIP that wassaved on the stack by the previous <A HREF="CALL.htm">CALL</A> instruction.<P><A HREF="RET.htm">RET</A> instructions may optionally specify an immediate operand. By addingthis constant to the new top-of-stack pointer, <A HREF="RET.htm">RET</A> effectively removes anyarguments that the calling program pushed on the stack before the executionof the <A HREF="CALL.htm">CALL</A> instruction.<P><A HREF="IRET.htm">IRET</A> (Return From Interrupt) returns control to an interrupted procedure.<A HREF="IRET.htm">IRET</A> differs from <A HREF="RET.htm">RET</A> in that it also pops the flags from the stack into theflags register. The flags are stored on the stack by the interruptmechanism.<H2>3.5.2  Conditional Transfer Instructions</H2>The conditional transfer instructions are jumps that may or may nottransfer control, depending on the state of the CPU flags when theinstruction executes.<H3>3.5.2.1  Conditional Jump Instructions</H3>Table 3-2 shows the conditional transfer mnemonics and theirinterpretations. The conditional jumps that are listed as pairs are actuallythe same instruction. The assembler provides the alternate mnemonics forgreater clarity within a program listing.<P>Conditional jump instructions contain a displacement which is added to theEIP register if the condition is true. The displacement may be a byte, aword, or a doubleword. The displacement is signed; therefore, it can be usedto jump forward or backward.<PRE>Table 3-2. Interpretation of Conditional TransfersUnsigned Conditional TransfersMnemonic         Condition Tested          "Jump If..."JA/JNBE           (CF or ZF) = 0           above/not below nor equalJAE/JNB           CF = 0                   above or equal/not belowJB/JNAE           CF = 1                   below/not above nor equalJBE/JNA           (CF or ZF) = 1           below or equal/not aboveJC                CF = 1                   carryJE/JZ             ZF = 1                   equal/zeroJNC               CF = 0                   not carryJNE/JNZ           ZF = 0                   not equal/not zeroJNP/JPO           PF = 0                   not parity/parity oddJP/JPE            PF = 1                   parity/parity evenSigned Conditional TransfersMnemonic         Condition Tested          "Jump If..."JG/JNLE          ((SF xor OF) or ZF) = 0   greater/not less nor equalJGE/JNL          (SF xor OF) = 0           greater or equal/not lessJL/JNGE          (SF xor OF) = 1           less/not greater nor equalJLE/JNG          ((SF xor OF) or ZF) = 1   less or equal/not greaterJNO              OF = 0                    not overflowJNS              SF = 0                    not sign (positive, including 0)JO               OF = 1                    overflowJS               SF = 1                    sign (negative)</PRE><H3>3.5.2.2  Loop Instructions</H3>The loop instructions are conditional jumps that use a value placed in ECXto specify the number of repetitions of a software loop. All loopinstructions automatically decrement ECX and terminate the loop when ECX=0.Four of the five loop instructions specify a condition involving ZF thatterminates the loop before ECX reaches zero.<P><A HREF="LOOP.htm">LOOP</A> (Loop While ECX Not Zero) is a conditional transfer that automaticallydecrements the ECX register before testing ECX for the branch condition. IfECX is non-zero, the program branches to the target label specified in theinstruction. The <A HREF="LOOP.htm">LOOP</A> instruction causes the repetition of a code sectionuntil the operation of the <A HREF="LOOP.htm">LOOP</A> instruction decrements ECX to a value ofzero. If <A HREF="LOOP.htm">LOOP</A> finds ECX=0, control transfers to the instruction immediatelyfollowing the <A HREF="LOOP.htm">LOOP</A> instruction. If the value of ECX is initially zero, thenthe <A HREF="LOOP.htm">LOOP</A> executes 2^(32) times.<P><A HREF="LOOPcond.htm">LOOPE</A> (Loop While Equal) and <A HREF="LOOPcond.htm">LOOPZ</A> (Loop While Zero) are synonyms for thesame instruction. These instructions automatically decrement the ECXregister before testing ECX and ZF for the branch conditions. If ECX isnon-zero and ZF=1, the program branches to the target label specified in theinstruction. If <A HREF="LOOPcond.htm">LOOPE</A> or <A HREF="LOOPcond.htm">LOOPZ</A> finds that ECX=0 or ZF=0, control transfersto the instruction immediately following the <A HREF="LOOPcond.htm">LOOPE</A> or<A HREF="LOOPcond.htm">LOOPZ</A> instruction.<P><A HREF="LOOPcond.htm">LOOPNE</A> (Loop While Not Equal) and <A HREF="LOOPcond.htm">LOOPNZ</A> (Loop While Not Zero) are synonymsfor the same instruction. These instructions automatically decrement the ECXregister before testing ECX and ZF for the branch conditions. If ECX isnon-zero and ZF=0, the program branches to the target label specified in theinstruction. If <A HREF="LOOPcond.htm">LOOPNE</A> or <A HREF="LOOPcond.htm">LOOPNZ</A> finds that ECX=0 or ZF=1, control transfersto the instruction immediately following the <A HREF="LOOPcond.htm">LOOPNE</A> or <A HREF="LOOPcond.htm">LOOPNZ</A> instruction.<H3>3.5.2.3  Executing a Loop or Repeat Zero Times</H3><A HREF="Jcc.htm">JCXZ</A> (Jump if ECX Zero) branches to the label specified in the instructionif it finds a value of zero in ECX. <A HREF="Jcc.htm">JCXZ</A> is useful in combination with the<A HREF="LOOP.htm">LOOP</A> instruction and with the string scan and compare instructions, all ofwhich decrement ECX. Sometimes, it is desirable to design a loop thatexecutes zero times if the count variable in ECX is initialized to zero.Because the <A HREF="LOOP.htm">LOOP</A> instructions (and repeat prefixes) decrement ECX beforethey test it, a loop will execute 2^(32) times if the program enters theloop with a zero value in ECX. A programmer may conveniently overcome thisproblem with <A HREF="Jcc.htm">JCXZ</A>, which enables the program to branch around the codewithin the loop if ECX is zero when <A HREF="Jcc.htm">JCXZ</A> executes. When used with repeatedstring scan and compare instructions, <A HREF="Jcc.htm">JCXZ</A> can determine whether therepetitions terminated due to zero in ECX or due to satisfaction of thescan or compare conditions.<H2>3.5.3  Software-Generated Interrupts</H2>The <A HREF="INT.htm">INT n</A>, <A HREF="INT.htm"INTO</A>, and <A HREF="BOUND.htm">BOUND</A> instructions allow the programmer to specify atransfer to an interrupt service routine from within a program.<P><A HREF="INT.htm">INT n</A> (Software Interrupt) activates the interrupt service routine thatcorresponds to the number coded within the instruction. The <A HREF="INT.htm">INT</A> instructionmay specify any interrupt type. Programmers may use this flexibility toimplement multiple types of internal interrupts or to test the operation ofinterrupt service routines. (Interrupts 0-31 are reserved by Intel.) Theinterrupt service routine terminates with an <A HREF="IRET.htm">IRET</A> instruction that returnscontrol to the instruction that follows <A HREF="INT.htm">INT n</A>.<P><A HREF="INT.htm">INTO</A> (Interrupt on Overflow) invokes interrupt 4 if OF is set. Interrupt 4is reserved for this purpose. OF is set by several arithmetic, logical, andstring instructions.<P><A HREF="BOUND.htm">BOUND</A> (Detect Value Out of Range) verifies that the signed value containedin the specified register lies within specified limits. An interrupt (<A HREF="INT.htm">INT</A> 5)occurs if the value contained in the register is less than the lower boundor greater than the upper bound.<P>The <A HREF="BOUND.htm">BOUND</A> instruction includes two operands. The first operand specifiesthe register being tested. The second operand contains the effectiverelative address of the two signed <A HREF="BOUND.htm">BOUND</A> limit values. The <A HREF="BOUND.htm">BOUND</A> instructionassumes that the upper limit and lower limit are in adjacent memorylocations. These limit values cannot be register operands; if they are, aninvalid opcode exception occurs.<P><A HREF="BOUND.htm">BOUND</A> is useful for checking array bounds before using a new index value toaccess an element within the array. <A HREF="BOUND.htm">BOUND</A> provides a simple way to check thevalue of an index register before the program overwrites information in alocation beyond the limit of the array.<P>The block of memory that specifies the lower and upper limits of an arraymight typically reside just before the array itself. This makes the arraybounds accessible at a constant offset from the beginning of the array.Because the address of the array will already be present in a register, thispractice avoids extra calculations to obtain the effective address of thearray bounds.<P>The upper and lower limit values may each be a word or a doubleword.<P><HR><P><B>up:</B> <A HREF="c03.htm">Chapter 3 -- Applications Instruction Set</A><BR><B>prev:</B> <A HREF="s03_04.htm">3.4  Logical Instructions</A><BR><B>next:</B> <A HREF="s03_06.htm">3.6  String and Character Translation Instructions</A></BODY>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -