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


 
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.编译和连接步骤
 
image 
 
3.使用objdump –D hello 反汇编
 
image 
 
 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM