您现在的位置是:首页 > 服务器相关

linux上测试汇编

batsom2020-12-11服务器相关

简介linux上测试汇编

测试汇编
vim hello.asm
;; nasm -f elf hello.asm; will output hello.o
;; ld -s -o hello hello.o

;; section, same to segment
segment .data      ; 数据段声明, 下列代码将放在数据段中
    msg db "Hello, world!", 0xA   ; 要输出的字符串
    len equ $ - msg         ; 字串长度

section .text      ; 代码段声明,下列代码将放入代码段中
global _start      ; 指定入口函数,global修饰是为了让外部可以引用_start
_start:         ; 在屏幕上显示一个字符串
    mov edx, len   ; 参数三:字符串长度
    mov ecx, msg   ; 参数二:要显示的字符串
    mov ebx, 1    ; 参数一:文件描述符(stdout)
    mov eax, 4    ; 系统调用号(sys_write)
    int 0x80     ; 调用内核功能
             ; 退出程序
    mov ebx, 0    ; 参数一:退出代码
    mov eax, 1    ; 系统调用号(sys_exit)
    int 0x80     ; 调用内核功能

编译:
nasm -f elf32 -g -F stabs hello.asm
ld -m elf_i386 -o hello -e main hello.o

执行:
./hello




 

郑重声明:

本站所有活动均为互联网所得,如有侵权请联系本站删除处理

随便看看

文章排行

本栏推荐

栏目更新