zoukankan      html  css  js  c++  java
  • 《汇编语言》-- 控制执行流程

    参考文献:

     《汇编语言程序设计》

    ............................................................................................................................................................................................... 

     控制执行流程学习,程序中遇到无条件分支时,指令指针自动跳转到另一个位置,可以使用无条件分支的有三种:

      跳转,调用,中断

      每一种无条件分支在程序中的行为都不同,可以决定在程序逻辑中使用哪一种,下面看一下这几种之间的区别,以及在汇编语言程序中实现它们

    一. 跳转

      跳转是汇编语言程序设计中最基本的分支类型,类似于高级语言中的GOTO语句,但是使用goto会被认为是不良的编码,但是在汇编在不会这么认为。

      实际上单一汇编跳转指令被汇编为跳转操作码的3种不同类型之一:

      短跳转,近跳转,远跳转

      这三种跳转类型由当前指令的内存位置和目的点的内存位置之间的距离决定的。依据跳过的字节数决定使用那种跳转类型

    举个栗子:

      

     1 .section .text
     2 .globl _start
     3 _start:
     4     nop
     5     movl $1, %eax
     6     jmp overhere
     7     movl $10, %ebx
     8     int $0x80
     9 overhere:
    10     movl $20, %ebx
    11     int $0x80

    执行程序:echo $?
    结果:20

     1 objdump -D jmptest
     2 
     3 jmptest:     文件格式 elf64-x86-64
     4 
     5 
     6 Disassembly of section .text:
     7 
     8 0000000000400078 <_start>:
     9   400078:    90                       nop
    10   400079:    b8 01 00 00 00           mov    $0x1,%eax
    11   40007e:    eb 07                    jmp    400087 <overhere>
    12   400080:    bb 0a 00 00 00           mov    $0xa,%ebx
    13   400085:    cd 80                    int    $0x80
    14 
    15 0000000000400087 <overhere>:
    16   400087:    bb 14 00 00 00           mov    $0x14,%ebx
    17   40008c:    cd 80                    int    $0x80
  • 相关阅读:
    How to change hostname on SLE
    How to install starDIct on suse OS?
    python logging usage
    How to reset password for unknow root
    How to use wget ?
    How to only capute sub-matched character by grep
    How to inspect who is caller of func and who is the class of instance
    How to use groovy script on jenkins
    Vim ide for shell development
    linux高性能服务器编程 (二) --IP协议详解
  • 原文地址:https://www.cnblogs.com/mysky007/p/11111780.html
Copyright © 2011-2022 走看看