码迷,mamicode.com
首页 > 其他好文 > 详细

as 汇编器

时间:2015-10-30 20:40:43      阅读:316      评论:0      收藏:0      [点我收藏+]

标签:

 

[root@localhost ~]# cat 1.s
 .file "write.s"
 .section .rodata
          hello: .string "hello, world!\n"
 
 .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 programs 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

as 汇编器

标签:

原文地址:http://www.cnblogs.com/zengkefu/p/4924263.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!