您的位置:首页 > 其它

as 汇编器

2015-10-30 20:02 176 查看
[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 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: