Linux環境下的一個彙編程序

vim hello.asm

section    .text
    ; The _start symbol must be declared for the linker (ld)
    global _start
_start:
    ; Prepare arguments for the sys_write system call:
    ;   - eax: system call number (sys_write)
    ;   - ebx: file descriptor (stdout)
    ;   - ecx: pointer to string
    ;   - edx: string length
    mov     edx, len1
    mov     ecx, msg1
    mov     ebx, 1
    mov     eax, 4

    ; Execute the sys_write system call
    int     0x80

    ; Now print the other message
    mov     edx, len2
    mov     ecx, msg2
    mov     ebx, 1
    mov     eax, 4
    int     0x80

    ; Execute sys_exit
    mov     eax, 1
    int     0x80

section    .data

msg1    db      'Hello,china,', 0xa
len1    equ     $ - msg1
msg2    db      'world!', 0xa
len2    equ     $ - msg2

然後執行下面命令:

nasm -f elf64 -o hello.o hello.asm
ld -o hello hello.o
./hello

使用的是centos,nasm 需要安裝。

nasm的用法教程
彙編基礎知識入門
8086架構與彙編
彙編語言視頻教程

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章