华南理工大学汇编原理课件05-1

上传人:xh****66 文档编号:61682429 上传时间:2018-12-09 格式:PPT 页数:50 大小:395.50KB
返回 下载 相关 举报
华南理工大学汇编原理课件05-1_第1页
第1页 / 共50页
华南理工大学汇编原理课件05-1_第2页
第2页 / 共50页
华南理工大学汇编原理课件05-1_第3页
第3页 / 共50页
华南理工大学汇编原理课件05-1_第4页
第4页 / 共50页
华南理工大学汇编原理课件05-1_第5页
第5页 / 共50页
点击查看更多>>
资源描述

《华南理工大学汇编原理课件05-1》由会员分享,可在线阅读,更多相关《华南理工大学汇编原理课件05-1(50页珍藏版)》请在金锄头文库上搜索。

1、Chapter 5,Branching and Looping 分支和循环,Textbook: 7 Program Logic and Control,Outline,The objective of this chapter is to describe the structures such as : if then , if then else (分支结构程序设计) while, until, for (循环结构程序设计),Transfer (控制转移类指令),Instructions that can transfer control outside the normal sequen

2、tial flow. By changing the offset value in IP or changing the value of IP and CS. jmp , jcc, loop,控制转移类指令通过改变IP(或同时修改CS和IP)值,实现程序执行顺序的改变,Short, near and far address,The assembler supports three types of addresses that are distinguish by their distance from the currently executing address.,3 types of

3、 addresses - short,A short address, limited to a distance of -128 (80H) to 127(7FH) bytes. A short address is reached by a 1-byte offset.,3 types of addresses - near,A near address, limited to a distance of -32768 (8000H) to 32767(7FFFH) bytes within the same segment. A near address is reached by a

4、1-word or 2-word offset.,3 types of addresses - far,A far address, which may be within the same segment at a distance over 32K, or in another segment. A far address is reached by a segment address and an offset.,Transfer instructions (控制转移类指令),Unconditional (无条件转移指令) Jump (跳转) Procedure (过程) Interru

5、pt (中断) Conditional (条件转移指令) Looping (循环指令),Unconditional Jumps 8086无条件转移,5.1,JMP Instruction,Unconditional : the operation transfers control under all circumstances. Operation: (IP) - (IP) + shift-value (CS) - (CS) of destination segment,JMP Instruction,Examples,JMP short, near, or far address ;lab

6、el / register / memory,jmp quit ;退出程序 quit: mov ax,4c00h ;退出并返回dos int 21h,JMP Instruction,A JMP operation to a label within -128 (80H) to +127 (7FH) bytes is a short jump. A JMP that exceeds -128 (80H) to +127 (7FH) bytes is a near jump (within 32K). A JMP that exceeds 32KB byte (within real model

7、memory system) becomes a far jump (from a segment to another ).,address,The assembler generates one byte for the operation (EB) and one byte for the operand.,Jmp s - jmp 0008 - EB03,Examples,The assembler generates one byte for the operation (EB) and one byte for the operand.,Examples,Jmp s - jmp 00

8、0B - EB03,JMP short / near / far address,Unconditional transfer instruction for JMP short / near / far address,JMP Instruction,Forward jump Backward jump,jmp quit ;退出程序 quit: mov ax,4c00h ;退出并返回dos int 21h,Examples,forever: mov ax, 0 jmp forever ;重复,Examples,Transfer type of JMP,Direct addressing vs

9、. Indirect addressing Intra-segment transfer vs. Inter-segment transfer,Intra-segment vs. Inter-segment,实际编程时,汇编程序会根据目标地址的距离,自动处理成短转移、近转移或远转移 程序员可用操作符short、near ptr 或far ptr 强制,Direct addressing vs. Indirect addressing,Direct addressing (直接寻址方式) 转移地址象立即数一样,直接包含在指令的机器代码中,就是直接寻址方式 Indirect addressing

10、(间接寻址方式) 转移地址在寄存器或主存单元中,就是通过寄存器或存储器的间接寻址方式,用标号表达,用寄存器或存储器操作数表达,Transfer type of JMP,4 types,Types, Intra-segment direct addressing 段内转移 直接寻址 Intra-segment indirect addressing 段内转移 间接寻址 Inter-segment direct addressing 段间转移 直接寻址 Inter-segment Indirect addressing 段间转移 间接寻址, Intra-segment direct address

11、ing,jmp again ; transfer again: dec cx ; label “again” jmp output ; transfer output: mov result,al ;label “output”,Examples,实际为相对寻址,JMP label ;IPIP+shift,(2) Intra-segment indirect addressing,jmp ax ; IPAX jmp word ptr 2000h ; IP2000h,Examples,JMP r16/m16 ;IPr16/m16, Inter-segment direct addressing,

12、jmp far ptr otherseg ; otherseg is in another segment,Examples,JMP far ptr label ; IPlabel的偏移地址 ; CSlabel的段地址, Inter-segment direct addressing,jmp far ptr s,Examples, Inter-segment Indirect addressing,mov word ptr bx,0 mov word ptr bx+2,1500h JMP far ptr bx ;转移到1500h:0,Examples,JMP far ptr mem ; IPm

13、em,CSmem+2,JMP指令:段内相对转移,JMP指令:段内寄存器间接转移,JMP指令:段间直接转移,JMP指令:段间间接转移,Conditional Jumps, Compare Instructions, and if Structure 条件转移、比较指令 和 if 结构,5.2,Conditional jump instruction,The processor supports a variety of conditional jump instructions that transfer control depending on settings in the flag reg

14、ister .,DEC CX JNZ A20 ; test the setting of ZF,Examples,label: Jnnn short-address ; 条件满足,发生转移:IPIP8位位移量 ; 条件不满足,顺序执行,Conditional jump instruction: CMP,cmp al,100 jb below ; if al100, jump to below sub al,100 ; else (al100), alal-100 below: ,执行比较指令之后,可以根据标志判断两个数是否相等、大小关系等,Examples,Conditional jump i

15、nstruction,For the 8086286, the distance for a conditional jump must be a short, within 128 to +127 byte. If the operation exceeds the limit, the assembler issues a message “relative jump out of range”. The 80386 and later processors allow reaching any address within 32K(=215).,label: Jnnn short-add

16、ress,Jnnn Instructions,Jnnn instructions transfer control depending on settings in the Flags register. (Table) not affect flags 1. Jumps based on Unsigned (logical) data 2. Jump based on signed (Arithmetic) data 3. Special arithmetic tests 1比较无符号数高低 2比较有符号数大小 3判断单个标志位状态及其他,Jnnn Instructions,实际虽然指令只有16条,但却有30个助记符 采用多个助记符,只是为了方便记忆和使用,Jumps based on Unsigned (logical) data (无符号数高低),Above -

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号