资源预览内容
第1页 / 共47页
第2页 / 共47页
第3页 / 共47页
第4页 / 共47页
第5页 / 共47页
第6页 / 共47页
第7页 / 共47页
第8页 / 共47页
第9页 / 共47页
第10页 / 共47页
亲,该文档总共47页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
1,微机原理与接口技术 Theory and Interface Technology of Microcomputer,北京化工大学 信息科学与技术学院 主讲教师: 郭青 guoqingmail.buct.edu.cn,2,Chapter 2 INSTRUCTION SET,3,2.6 Program Control Instructions,控制转移指令 The program control instructions direct the flow of a program and allow the flow to change.,Program Control instructions include Jump 转移指令Loop 循环控制指令Call 过程调用指令Return 过程返回指令Interrupt 中断指令,4,2.6.1 The Jump Group,转移指令 Unconditional Jump (JMP) 无条件转移,JMP allows the programmer to skip sections of a program and branch to any part of the memory for the next instruction.Short jumpNear jumpFar jumpIndirect jump,5,Short Jump,1) Short Jump 段内直接短转移,JMP Short_label,; (IP) (IP) + 8-bits disp,Relative jump. 相对转移 Instead of a jump address, a distance, or displacement, follows the opcode. 1 byte disp range -128 +127 A label is a symbolic name for a memory address 指令给出一个语句标号,但机器指令操作数不是地址,而是此标号相对于当前IP的偏移量,用8位补码表示。 转移范围 相对于当前IP -128 +127,6,Short Jump,Example:XOR BX, BX START: MOV AX, 1ADD AX, BXJMP SHORT NEXT NEXT: MOV BX, AXJMP START,Assume: (CS) = 1000H,标号先引用,后定义,加SHORT限定,标号先定义,后引用,不加SHORT,由汇编程序自动生成,0002H,001EH,0020H,IP,7,NEAR Jump,2) Near Jump 段内直接转移,JMP near_label,; (IP) (IP) + 16-bits disp,Relative jump, similar to short jump 2 bytes disp range 32K The label is in the current code segment located within 32K bytes from the near jump instruction. Three bytes instruction containing an opcode followed by a signed 16-bits displacement. 类似于Short jump,指令给出一个语句标号,此标号地址相对于当前IP的偏移量为16位补码 转移范围 同一代码段中相对于当前IP -32768 +32767,8,Near Jump,Example:XOR BX, BX START: MOV AX, 1ADD AX, BXJMP NEXT NEXT: MOV BX, AXJMP START,Assume: (CS) = 1000H,0002H,0200H,0202H,IP,9,FAR Jump,3) Far Jump 段间直接转移,JMP far_label,; (IP) OFFSET far_label ; (CS) SEG far_label,New segment and offset address Five bytes instructiona byte opcode followed by 4 bytes address Bytes 2 and 3 new offset address Bytes 4 and 5 new segment address 指令给出的标号地址在另一代码段中,5字节指令 第一字节:操作码 2,3字节:偏移地址 IP 4,5字节:段地址 CS,10,FAR Jump,Example: JMP LABEL_DECLARED_FAR JMP FAR PTR LABEL_NAME,LABEL_DECLARED_FAR ;另一代码段,已定义 FAR PTR LABEL_NAME ;用PTR指定,11,Indirect Jump,Indirect Jump 间接转移指令 4.1) Jump with Register operands,JMP Reg16,; (IP) (Reg16),Intra-segment jump The contents of the 16-bits register is the offset address. 指令将16位寄存器的内容作为偏移地址取代原来IP的内容,实现段内转移。 Example:JMP AX,12,Indirect Jump,4.2) Near indirect jump with memory operands,JMP MEM16,; (IP) (MEM16),Intra-segment jump,word type operands The contents of the addressed memory location is the offset address. The operands can use all MEM addressing modes. 指令将存储器中的字数据作为偏移地址取代原来IP的内容,实现段内转移。,13,Indirect Jump,Example: JMP TABEL BX JMP ALPHA_WORD JMP WORD PTR BPSI常用于多分支转移。,14,Indirect Jump,4.3) Far indirect jump,JMP MEM32,; (IP) (MEM32) ; (CS) (MEM32+2),Inter-segment jump Double-word type operands The least 2 bytes of the MEM content offset address. The most 2 bytes of MEM content segment address. The operands can use all MEM addressing modes. 双字数据的低字为偏移地址取代原来IP的内容,高字为段地址给CS,实现段间转移。,15,Indirect Jump,Example: JMP VAR_DOUBLEWORD ;预先定义为双字数据 JMP DWORD PTR BPSI JMP FAR PTR TABLEDI,16,2. Conditional Jump,条件转移指令 Always short jump. 转移范围:当前IP -128 +127 The conditional jump instruction test the following flag bits: SF, ZF, CF, PF and OF. 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. 条件转移指令测试标志位。 如果条件满足,转移到目标地址; 条件不满足,顺序执行下一条指令。,17,两个无符号数比较后根据其比较结果形成的4条条件转移指令 此类指令一般跟在比较或减法指令后面,18,两个带符号数比较后根据其比较结果形成的4条条件转移指令 一般跟在比较或者减法指令后面,19,根据CF、ZF、SF、OF、PF的状态形成的10条条件转移指令,20,2.6.2 LOOP,循环控制指令 1)LOOP 无条件循环,LOOP Short_label,LOOP instruction is a combination of a decrement CX and JNZ conditional jump. Short Jump Procedure: Decrements CX If CX 0, it jumps to the address indicated by the label If CX = 0, the next sequential instruction execute 转移范围同条件转移指令。执行时,CX-1,然后判断CX是否为0;不为0,转移。为0,顺序执行。,21,LOOPE,2)LOOPE/LOOPZ (Loop while equal/zero),LOOPE/LOOPZ Short_label,LOOPE/LOOPZ instruction jumps if CX 0 while an equal condition exists. It will exit the loop if the condition is not equal or if the CX decrements to 0. 执行时,先CX-1,然后判断。 如CX 0,且ZF=1,转移。 如任一条件不满足,则顺序执行下一条指令。,22,LOOPNE,3)LOOPNE/LOOPNZ (Loop while not equal/zero),LOOPNE/LOOPNZ Short_label,LOOPNE/LOOPNZ instruction jumps if CX 0 while an not-equal condition exists. It will exit the loop if the condition is equal or if the CX decrements to 0. 执行时,先CX-1,然后判断。 如CX 0,且ZF=0,转移。 如任一条件不满足,则顺序执行下一条指令。,23,LOOP Example,例:在内存的数据段中存放了若干个8位带符号数,数据块的长度为COUNT(不超过255),首地址为TABLE,试统计其中正元素、负元素及零元素的个数,并分别将个数存入PLUS、MINUS和ZERO单元。,分析: 先清零PLUS、MINUS和ZERO单元 取数据到AL中,判断SF及ZF 零,ZERO+1 负数,MINUS+1 正数,PLUS+1,24,LOOP Example,XOR AL, AL MOV PLUS, AL MOV MINUS, AL MOV ZERO, AL LEA SI, TABLE MOV CX, COUNT CLD LODSB OR AL, AL JS X1 JZ X2 INC PLUS JMP NEXT INC MINUS JMP NEXT INC ZERO LOOP CHECK,
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号