section .data
msg db "Hello , world", 13, 10
len equ $-msg
section .text
global _start
_start:
mov eax, 4
mov ebx, 1
mov ecx, msg
mov edx, len
int 0x80
mov eax, 1
mov ebx, 0
int 0x80
具体思路:
使用通过0x80软中断来使用Linux系统调用达到输出字符串的目的。
调用的功能可对比 write函数 write(int fd,const void *buf,size_t count)
进行调用时,eax中存放功能号,此处为4,
ebx中存放第一个参数,此处为 文件描述符
ecx中存放第二个参数,此处为 输出字符串的指针,即msg
edx中存放第三个参数,此处为 字符串的长度
之后 调用中断 0x80,输出字符串
输出完成之后,再次以相同的方法使用0x80中断,此次的功能号为1,代表退出
最后退出程序
编译及运行(此处假设文件名为hello.s):
nasm -f elf hello.s (如果为64位系统,则应为nasm -f elf64 hello.s)
ld -o hello hello.o