zoukankan      html  css  js  c++  java
  • 汇编语言笔记 转移指令的原理

    原文地址:   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查看汇编指令,就可以知道这个程序为什么可以正常退出啦

  • 相关阅读:
    shell——变量
    xxx is not in the sudoers file.This incident will be reported.的解决方法
    百度面试回忆
    iOS网络协议 HTTP/TCP/IP浅析
    使用xib封装一个自定义view的步骤
    修改了系统自带头文件后,Xcode会报错
    字典转模型规范化
    文本属性Attributes
    苹果API常用英语名词
    命令行 -- 命令"%cd%"
  • 原文地址:https://www.cnblogs.com/LittleRedPoint/p/4009120.html
Copyright © 2011-2022 走看看