免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1875 | 回复: 0
打印 上一主题 下一主题

AT&T汇编语言程序设计之----Hello World [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-12-19 14:29 |只看该作者 |倒序浏览

                                                                                                                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
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP