- 论坛徽章:
- 0
|
AT&T汇编语言是gcc使用的汇编语言,并且在大多数Unix和Linux系统上都使用AT&T汇编语言。他和Intel汇编都是IA-32平台的主要汇编语言,不同的是,Intel汇编主要运用在Windows系统.而AT&T还广泛运用在嵌入式领域,下面是AT&T语言的Hello World!
HelloWorld.s
#AT&T assemble , Hello World
.section .datastring: .ascii "Hello World!\n"
.section .text.globl _start_start: nop #cpu do nothing, this insctruction write for debug with gdb
#the follow 5 lines is: write(int file_descriptor, void *buffer, size_t length) movl $4, %eax #Linux soft interrupt, call number in eax, 4 is for system-call write movl $1, %ebx #file descriptor in ebx, stdout's file descriptor is 1 movl $string, %ecx #buffer in ecx, this line move string's address to ecx movl $13, %edx #buffer's size in edx int $0x80 #Linux soft interrupt
#the follow 3 lines is: exit(int status_code) movl $1, %eax #system call: exit movl $0, %ebx #status code in ebx int $0x80 #Linux soft interrupt
在Linux下编译和链接此文件的指令为:
编译:
as -o HelloWorld.o HelloWorld.s
链接:
ld -o HelloWorld HelloWorld.o
在shell下运行:
$./HelloWorld
即可看到在shell下输出 Hello World!
在shell下查看退出码:
$echo $?
可以看到退出码为 0
HelloWorld.s源代码
![]()
文件:HelloWorld.tar.gz
大小:0KB
下载:
下载
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/104217/showart_2125952.html |
|