Hello World——Linux汇编
2011-07-14 09:54
260 查看
采用AT&T语法。
32位:
1 .section .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 .section .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
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
20 mov $0, %rdi # exit (0)
21 syscall # previous 'int $0x80' in i386
编译命令一样:(假设汇编源文件名为:hello.s)
$ as hello.s -o hello.o
$ ld hello.o -o hello
主要区别:
(1)系统调用号不同了,比如sys_write在i368中是4,x86-64中是1;sys_exit在i386中是1,而x86_64中是60;
(2)系统调用所使用的6个参数寄存器也变了,i386中分别是ebx/ecx/edx/esi/edi/ebp,x86_64中则使用rdi/rsi/rdx/r10/r8/r9,显然不只是“e”改成“r”那么简单;
(3)执行系统调用的指令,i386中使用“int 80”,而x86-64中使用“syscall”。
32位:
1 .section .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 .section .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
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
20 mov $0, %rdi # exit (0)
21 syscall # previous 'int $0x80' in i386
编译命令一样:(假设汇编源文件名为:hello.s)
$ as hello.s -o hello.o
$ ld hello.o -o hello
主要区别:
(1)系统调用号不同了,比如sys_write在i368中是4,x86-64中是1;sys_exit在i386中是1,而x86_64中是60;
(2)系统调用所使用的6个参数寄存器也变了,i386中分别是ebx/ecx/edx/esi/edi/ebp,x86_64中则使用rdi/rsi/rdx/r10/r8/r9,显然不只是“e”改成“r”那么简单;
(3)执行系统调用的指令,i386中使用“int 80”,而x86-64中使用“syscall”。
相关文章推荐
- linux下使用汇编语言编写hello world!程序
- linux 下at&t语法的汇编之hello world!!
- Linux 下 AT&T汇编 - Hello World
- Hello World——Linux汇编
- linux 64位汇编之hello world
- linux下使用汇编语言编写hello world!程序
- Hello World——Linux汇编
- Hello World——Linux汇编
- Hello World——Linux汇编
- linux汇编之——(6)反汇编条件控制
- [Kernel] Linux 4.10.0+ 下编译安装内核模块(Hello World为例)
- linux下64位汇编的系统调用(1)
- linux下64位汇编的系统调用(5)
- 汇编写出"hello world!"
- 第一个C程序内嵌汇编(Linux下)
- Linux驱动程序入门—Hello World
- linux2.6驱动模块编写的一个例子-hello world
- linux下的C语言开发(AT&T 汇编语言)
- Linux汇编教程04:寻址方式
- CentOS6.4(linux)下编写C程序(hello world)步骤及注意事项