• 汇编语言笔记 转移指令的原理


    原文地址:   http://www.cnblogs.com/dennisOne

    ☞8086CPU转移指令分类

    • 无条件转移指令(如:jmp)
    • 条件转移指令
    • 循环指令(如:loop)
    • 过程
    • 中断

       

    ☞操作符offset

    offset在汇编语言中是由汇编器处理的符号,它的功能是取标号的偏移地址。

       

    ☞jmp指令

    类型

    功能

    示例

    jmp short 标号

    (段内短转移)

    复制代码
    assume cs:code
    code segment
    start: mov ax, 0
        jmp short s
        add ax, 1
    s:    inc ax
    code ends
    end start
    复制代码

    jmp near ptr 标号

    (段内近转移)

      

    jmp far ptr 标号

    (段间转移)

    复制代码
    assume cs:code
    code segment
    start: mov ax, 0
        mov bx, 0
        jmp far ptr s
        db 256 dup (0)
    code ends
    end start
    复制代码

    jmp 16位reg

    (段内转移)

    设置:(IP)=(16位reg)

    编译器根据情况判断段内short/near转移

      

    jmp word ptr 内存单元地址

    (段内转移)

    mov ax, 0123H
    mov ds:[0], ax
    jmp word ptr ds:[0]

    jmp dword ptr 内存单元地址

    (段间转移)

    mov ax, 0123H
    mov ds:[0], ax
    mov word ptr ds:[2], 0
    jmp dword ptr ds:[0]

    jmp 2000:0100

    (段间转移)

       

    • 举例说明:

       

    ☞条件转移指令和循环指令

    所有的有条件转移指令和循环指令都是短转移,在对应的机器码中包含转移的位移,而不是目的地址,而不是目的地址。对IP的修改范围都为:-128~127。

    类型

    功能

    jcxz

    (条件转移指令)

    loop

    (循环指令)

      

       

    ☞根据位移进行转移的指令

    1 jmp short 标号
    2 jmp near ptr 标号
    3 jcxz 标号
    4 loop 标号

    等几种汇编指令,它们对IP的修改是根据转移目的地址和转移起始地址之间的位移(补码)来进行的,而不是在对应的机器码包含转移的目的地址。

    分析一个奇怪的程序:

    复制代码
     1 assume cs: codesg
     2 
     3 codesg segment
     4         mov ax, 4c00h
     5         int 21h
     6             
     7 start:    
     8         mov ax, 0
     9 s:      nop  ;jmp short s1
    10         nop
    11             
    12         mov di, offset s
    13         mov si, offset s2
    14         mov ax, cs:[si]
    15         mov cs:[di], ax
    16             
    17 s0:     jmp short s
    18         
    19 s1:     mov ax, 0
    20         int 21h
    21         mov ax, 0
    22             
    23 s2:     jmp short s1
    24         nop
    25 
    26 codesg ends
    27 
    28 end start 
    复制代码

    通过debug查看汇编指令,就可以知道这个程序为什么可以正常退出啦

  • 相关阅读:
    生成TXT下载并以逗号分隔
    使用javascript绑定键盘enter事件到asp.net的button控件 .
    学习wpf播放视频音频的两种不同方法
    批量修改数据库表的架构sql
    如何修改Sql2005注册服务器名称
    虚拟化之Hypervisor
    JAVA环境配置
    centos系统网卡配置详解
    Kali Linux安装
    Linux扩容新增磁盘分区挂载fdisk
  • 原文地址:https://www.cnblogs.com/LittleRedPoint/p/4009120.html
Copyright © 2020-2023  润新知