哪位好心人帮偶写了个linux x86_64汇编的Hello World吧。

晨星 2009-08-26 10:56:47
基于“write”系统调用就可以。
要是帮偶提供一点学习LINUX x86_64汇编的资料就更好了。
谢谢。
...全文
376 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
threenewbee 2009-08-26
  • 打赏
  • 举报
回复
乱写个。
msg db ‘Hello, world!‘,0xa
len equ $ - msg
_start:
mov rdx,len ;message length
mov rcx,msg ;message to write
mov rbx,1 ;file descriptor (stdout)
mov rax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov rax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
slowgrace 2009-08-26
  • 打赏
  • 举报
回复
还真改过来了,再帮你顶一哈
slowgrace 2009-08-26
  • 打赏
  • 举报
回复
Hello World!

顺便看看我的昵称有木有改过来。
loveisbug 2009-08-26
  • 打赏
  • 举报
回复
先看博客上的,看不大懂,看了这里的解释区别,明白点了。
threenewbee 2009-08-26
  • 打赏
  • 举报
回复
学习!
晨星 2009-08-26
  • 打赏
  • 举报
回复
非常感谢楼上。根据楼上写的,又参考了网上搜出来的其它一些片断,刚刚调通了。
看起来LINUX-64跟32位的还是有很大区别的,比如:
(1)系统调用号改了,比如sys_write原来是4,x64中是1,sys_exit原来是1,x64中是60;
(2)系统调用时所使用的寄存器也变了,x64中分别使用rdi/rsi/rdx传递前三个参数,而不是原来的ebx/ecx/edx直接扩展来的rbx/rcx/rdx;
(3)系统调用使用“syscall”而不是“int 80”。

下面是我自己写的32位和64位的,不过采用的是AT&T语法。
32位:

1 .text
2 .global _start
3
4 msg:
5 .ascii "Hello World!\n"
6 msg_end:
7 .equ len, msg_end - msg
8 .equ SYS_write, 4
9 .equ SYS_exit, 1
10
11 _start:
12
13 mov $SYS_write, %eax # system call number
14 mov $1, %ebx # file descriptor (stdout)
15 mov $msg, %ecx # message to write
16 mov $len, %edx # message length.
17 int $0x80 # system call
18
19 mov $SYS_exit, %eax # system call number
20 mov $0, %ebx # exit (0)
21 int $0x80 # system call

64位:

1 .text
2 .global _start
3
4 msg:
5 .ascii "Hello World!\n"
6 msg_end:
7 .equ len, msg_end - msg
8 .equ SYS_write, 1
9 .equ SYS_exit, 60
10
11 _start:
12
13 mov $SYS_write, %rax # system call number (sys_write)
14 mov $1, %rdi # file descriptor (stdout)
15 mov $msg, %rsi # message to write
16 mov $len, %rdx # message length.
17 syscall # previous 'int $0x80' in i386
18
19 mov $SYS_exit, %rax # system call number (sys_exit)
20 mov $0, %rdi # exit (0)
21 syscall # previous 'int $0x80' in i386

21,459

社区成员

发帖
与我相关
我的任务
社区描述
汇编语言(Assembly Language)是任何一种用于电子计算机、微处理器、微控制器或其他可编程器件的低级语言,亦称为符号语言。
社区管理员
  • 汇编语言
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧