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