资源预览内容
第1页 / 共42页
第2页 / 共42页
第3页 / 共42页
第4页 / 共42页
第5页 / 共42页
第6页 / 共42页
第7页 / 共42页
第8页 / 共42页
第9页 / 共42页
第10页 / 共42页
亲,该文档总共42页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
CHAPTER 6 Program Control Instructions (程序控制指令)(P. 183),6-1 THE JUMP GROUP,Unconditional Jump Conditional Jumps LOOP,6-1-1 Unconditional Jump (无条件转移指令)(P. 184),The unconditional jump instruction, JMP, allows the programmer to skip sections of a program and branch to any part of the memory for the next instruction. Three types of unconditional jump instructions are available to the microprocessor: Short jump Near jump Far jump Jumps with Register Operands Indirect jumps Using an Index,Short jump (短转移)(P. 184),Format JMP SHORT LABEL Machine language,Opcode,Operation IPIPDisplacement,Note: The short jump displacement is a distance represented by a one-byte signed number whose value ranges between +127 and 128. The short jump is an intrasegment jump that allows branches to memory locations within +127 and 128 bytes from the address following the jump. Short jump is relative program memory addressing.,1000A,10009,10008,10007,10006,10005,10004,10003,10002,10001,10000,Memory,JMP,04,CS=1000H IP=0002H,FIGURE 6-2 A short jump to four memory locations beyond the address of the next instruction,New IP=IP+04 New IP=0006H,0000 33 DB XOR BX,BX 0002 B8 0001 START: MOV AX,1 0005 03 C3 ADD AX,BX 0007 EB 17 JMP SHORT NEXT0020 8B D8 NEXT: MOV BX,AX 0022 EB DE JMP SHORT START,Machine Language,Assembly Language,Offset,Near jump (近转移)(P. 185),Format JMP (NEAR PTR) LABEL Machine language,Opcode,Operation IPIPDisplacement,Note: The near jump displacement is a distance represented by a signed 16-bit number whose value ranges between +32767 and 32768. A near jump is an intrasegment jump that can jump to any memory location within the current real mode code segment. Short jump is relative program memory addressing.,1000A,10009,10008,10007,10006,10005,10004,10003,10002,10001,10000,Memory,JMP,02,FIGURE 6-3 A near jump that adds the displacement (0002H) to the contents of IP,00,0000 33 DB XOR BX,BX 0002 B8 0001 START: MOV AX,1 0005 03 C3 ADD AX,BX 0007 E9 F601 JMP NEXT0200 8B D8 NEXT: MOV BX,AX 0202 E9 FDFD JMP START,Offset,Machine Language,Assembly Language,Far jump (远转移)(P. 186),Format JMP FAR PTR LABEL Machine language,Opcode,Operation IPIP High, IP Low CSCS High, CS Low,A far jump instruction obtains a new segment and offset address to accomplish the jump. A far jump is an intersegment jump that accesses any location within the first 1M byte of memory in the real mode. A far jump is direct program memory addressing.,A3128,A3127,A3126,10004,10003,10002,10001,10000,Memory,JMP,27,FIGURE 6-4 A far jump instruction replaces the contents of both CS and IP with four bytes following the opcode.,01,00,A3,10005,EXTRN UP:FAR0000 33 DB XOR BX,BX 0002 B8 0001 START: MOV AX,1 0005 03 C3 ADD AX,BX 0007 E9 F601 JMP NEXT0200 8B D8 NEXT: MOV BX,AX 0202 EA 0002 - JMP FAR PTR START0207 EA 0000 - JMP UP,Offset,Machine Language,Assembly Language,Jumps with Register Operands (带寄存器操作数的转移)(P. 181),Format JMP 16reg Operation IP 16reg For example, the JMP AX instruction copies the contents of the AX register into the IP when the jump occurs.,Notes The 16reg represents any 16-bit register except segment registers. The address of the jump is in the register specified by the jump instruction. A jump with register operand is intrasegment jump that allows a jump to any location within the current code segment. A jump with register operand is indirect program memory addressing.,Indirect jumps Using an Index (使用变址的间接转移)(P. 188),The indirect jumps using an index use the form of addressing to directly access the jump table. The assembler assumes that the jump is near unless the FAR PTR directive indicates a far jump instruction.,TABLE DW ONE ;lookup tableDW TWODW THREE JMP TABLE SI ;IP(TABLE+SI+1,TABLE+SI),6-1-2 Conditional Jumps (条件转移)(P. 189),The conditional jump instructions test the following flag bits: sign (S), zero (Z), carry (C), parity (P), and overflow (O). If the condition under test is true, a branch to the label associated with the jump instruction occurs. If the condition is false, the next sequential step in the program executes. For example, a JC will jump if the carry bit is set.,Conditional jump instructions are always short jumps in the 8086 microprocessor. Conditional jump instructions often follow the CMP or TEST instruction. Table 6-1 lists all the conditional jump instructions with their test conditions.,TABLE 6-1 Conditional jump instructions,TABLE 6-1 Conditional jump instructions (continued),FIGURE 6-5 Signed and unsigned numbers follow different orders,6-1-3 LOOP (P. 186),Format LOOP LABEL Operation LOOP decrements CX; if CX0, it jumps to the address indicated by the label; If CX becomes a 0, the next sequential instruction executes. Compare the following instructions: LOOP LABEL DEC CXJNZ LABEL,EXAMPLE 6-6 ;A program that sums the contents of BLOCK1 and BLOCK2;and stores the results over top of the data in BLOCK2.MODEL SMALL ;select SMALL model.DATA ;start of DATA segmentBLOCK1 DW 100 DUP(?) ;100 bytes for BLOCK1BLOCK2 DW 100 DUP(?) ; 100 bytes for BLOCK2 .CODE ;start of CODE segment.STARTUP ;start of programMOV AX,DS ;overlap DS and ESMOV ES,AXCLD ;select incrementMOV CX,100 ;load count of 100MOV SI,OFFSET BLOCK1 ;address BLOCK1MOV DI,OFFSET BLOCK2 ; address BLOCK2L1: LODSW ;load AX with BLOCK1ADD AX,ES:DI ;add BLOCK2 data to AXSTOSW ;stare sum in BLOCK2LOOP L1 ;repeat 100 times.EXIT ;exit to DOSEND ;end of file,
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号