第一个helloworld程序

; hello.asm

section .data
        msg db "hello, world",13,10,0

section .bss

section .text
        global main
main:
        mov rax,1 ; 写
        mov rdi, 1 ; 到标准设备-屏幕
        mov rsi,msg ; 输出地址
        mov rdx,14; 输出长度
        syscall ;系统调用
        mov rax,60 ;退出
        mov rdi,0;退出错误码 0
        syscall

  编译脚本

# hello.asm
hello:  hello.o
        gcc -o hello hello.o -no-pie

hello.o:hello.asm
        nasm -f elf64 -g -F dwarf hello.asm -l hello.lst

# hello 依赖hello.o
# hello.o 依赖hello.asm
# hello.asm 编译按照elf64格式 -f elf64
# 生成debug 文件按照dwarf 格式 -g -F dwarf
# 生成lst文件 -l 

  

posted on 2022-10-31 17:51  金凯旋  阅读(37)  评论(0)    收藏  举报

导航