红联Linux门户
Linux帮助

Ubuntu下用as汇编器编写hello.S文件

发布时间:2016-02-07 09:08:33来源:linux网站作者:justinzhang

1.源代码
.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
movl    $len,%edx    # third argument: message length
movl    $msg,%ecx    # second argument: pointer to message to write
movl    $1,%ebx        # first argument: file handle (stdout)
movl    $4,%eax        # system call number (sys_write)
int    $0x80        # call kernel

# and exit

movl    $0,%ebx        # first argument: exit code
movl    $1,%eax        # system call number (sys_exit)
int    $0x80        # call kernel

.data                    # section declaration

msg:
.ascii    "Hello, world!\n"    # our dear string
len = . - msg            # length of our dear string


2.编译和连接步骤

Ubuntu下用as汇编器编写hello.S文件


3.使用objdump –D hello 反汇编

Ubuntu下用as汇编器编写hello.S文件


本文永久更新地址:http://www.linuxdiyf.com/linux/17921.html