zoukankan      html  css  js  c++  java
  • CentOS7写汇编并编译运行汇编代码

    1.下载nasm编译器

      下载地址是https://www.nasm.us/pub/nasm/releasebuilds/

    wget https://www.nasm.us/pub/nasm/releasebuilds/2.14/nasm-2.14.tar.gz

    2.解压安装nasm

    tar -xvzf nasm-2.14.tar.gz 

    3.进入到nasm的解压目录中编译并安装nasm

    cd nasm-2.14         #进入nasm的解压目录
    
    ./configure             #配置
    
    make       #编译
    
    make install   #安装
        

    4.一段可以输出Hello World的汇编代码

    section .data                           ;section declaration
    msg     db      "Hello, world!",0xA     ;our dear string
    len     equ     $ - msg                 ;length of our dear string
    section .text                           ;section declaration
                           ;we must export the entry point to the ELF linker or
       global _start       ;loader. They conventionally recognize _start as their
                           ;entry point. Use ld -e foo to override the default.
    _start:
    ;write our string to stdout
           mov     eax,4   ;system call number (sys_write)
           mov     ebx,1   ;first argument: file handle (stdout)
           mov     ecx,msg ;second argument: pointer to message to write
           mov     edx,len ;third argument: message length
           int     0x80    ;call kernel
    ;and exit
           mov     eax,1   ;system call number (sys_exit)
           xor     ebx,ebx ;first syscall argument: exit code
           int     0x80    ;call kernel

      将它保存为HelloWorld.s文件。

    5.编译该汇编代码

    nasm -f elf64 HelloWorld.s -o HelloWorld.o

    6.链接生成可执行文件

    ld -s HelloWorld.o -o HelloWorld.out

    7.执行程序

    ./HelloWorld.out

    8.执行结果如下

    [root@CentOs64-7 Assembly]# ./HelloWorld.out 
    Hello, world!

      转载自:https://blog.csdn.net/weiyuanzhuo/article/details/52382611

  • 相关阅读:
    leetcode ---Search a 2D Matrix
    leetcode ---Search for a Range
    LeetCode--Search in Rotated Sorted Array
    LeetCode--setatrixzeroes
    LeetCode--sortColor
    LeetCode--Spiral Matrix
    java io类 和servlet类 的UML图表示
    servlet web.xml配置详解
    解决json日期格式带T问题
    在拦截器中获取请求参数,[Ljava.lang.String; cannot be cast to java.lang.String报错
  • 原文地址:https://www.cnblogs.com/ToBeExpert/p/10632578.html
Copyright © 2011-2022 走看看