• as 汇编器


    [root@localhost ~]# cat 1.s
     .file "write.s"
     .section .rodata
              hello: .string "hello, world!
    "
     
     .section .text
     .global _start
    
     _start:
     movl $4,     %eax  # syscall number for write function
     movl $1,     %ebx  # 1 standand for stdout
     movl $hello, %ecx  # the second argument of write function 
     movl $14,    %edx  # the third argument of write function
     int  $0x80         # interrupt to call write
     movl $1,     %eax  # syscall number for sys_exit function
     xorl %ebx,   %ebx  # the argument for sys_exit function
     int  $0x80         # interrupt to call sys_exit
     
     ret                # return to the caller of the function

    编绎:
    as -o 1.o 1.s

    链接:

    ld -o 1 1.o 

    执行:

    [root@localhost ~]# ./1
    hello, world!

    Usage: objdump <option(s)> <file(s)>
     Display information from object <file(s)>.
     At least one of the following switches must be given:
      -a, --archive-headers    Display archive header information
      -f, --file-headers       Display the contents of the overall file header
      -p, --private-headers    Display object format specific file header contents
      -h, --[section-]headers  Display the contents of the section headers
      -x, --all-headers        Display the contents of all headers
      -d, --disassemble        Display assembler contents of executable sections
      -D, --disassemble-all    Display assembler contents of all sections
      -S, --source             Intermix source code with disassembly
      -s, --full-contents      Display the full contents of all sections requested
      -g, --debugging          Display debug information in object file
      -e, --debugging-tags     Display debug information using ctags style
      -G, --stabs              Display (in raw form) any STABS info in the file
      -W, --dwarf              Display DWARF info in the file
      -t, --syms               Display the contents of the symbol table(s)
      -T, --dynamic-syms       Display the contents of the dynamic symbol table
      -r, --reloc              Display the relocation entries in the file
      -R, --dynamic-reloc      Display the dynamic relocation entries in the file
      @<file>                  Read options from <file>
      -v, --version            Display this program's version number
      -i, --info               List object formats and architectures supported
      -H, --help               Display this information
    [root@localhost ~]# objdump -D ./1.o
    
    ./1.o:     file format elf64-x86-64
    
    Disassembly of section .text:
    
    0000000000000000 <_start>:
       0:   b8 04 00 00 00          mov    $0x4,%eax
       5:   bb 01 00 00 00          mov    $0x1,%ebx
       a:   b9 00 00 00 00          mov    $0x0,%ecx
       f:   ba 0e 00 00 00          mov    $0xe,%edx
      14:   cd 80                   int    $0x80
      16:   b8 01 00 00 00          mov    $0x1,%eax
      1b:   31 db                   xor    %ebx,%ebx
      1d:   cd 80                   int    $0x80
      1f:   c3                      retq   
    Disassembly of section .rodata:
    
    0000000000000000 <hello>:
       0:   68 65 6c 6c 6f          pushq  $0x6f6c6c65
       5:   2c 20                   sub    $0x20,%al
       7:   77 6f                   ja     78 <_start+0x78>
       9:   72 6c                   jb     77 <_start+0x77>
       b:   64 21 0a                and    %ecx,%fs:(%rdx)
            ...

     http://blog.csdn.net/geekcome/article/details/6216634

  • 相关阅读:
    【转载】C++针对ini配置文件读写大全
    CString向char类型转化 ---“=”: 无法从“wchar_t *”转换为“char *
    使用了非标准扩展:“xxx”使用 SEH,并且“xxx”有析构函数
    16进制串hex与ASCII字符串相互转换
    【转载】CCombobox使用大全
    获取c++ edit控件内容
    [转载]C++ CString与int 互转
    MacOS Cocos2d-x-3.2 创建HelloWorld项目
    构建之法阅读笔记6--敏捷开发2
    进度条--第十二周
  • 原文地址:https://www.cnblogs.com/zengkefu/p/4924263.html
Copyright © 2020-2023  润新知