as编写hello,world

来源:互联网 发布:mac os系统dmg镜像 编辑:程序博客网 时间:2024/05/16 15:14
.text.global _start_start:        movl $len,%edx        movl $msg,%ecx        movl $1,%ebx        movl $4,%eax        int $0x80        movl $0,%ebx        movl $1,%eax        int $0x80.datamsg:        .ascii "hello,world\n"        len=.-msg        .ascii "after hello\n"        len2=.-msg

我们来看代码段部分,.data表示一个代码段的开始,msg:标号仅仅给编译器看的,它只代表当前地址。len=.-msg得到数据段第一个字符串长度,同理len2是第一个字符串和第二个字符串长度之和。_start代表as汇编程序的默认入口。movl $msg,%ecx,将标号代表的地址放到ecx中。上述程序输出:hello,world。如果把代码段movl $len,%edx改成 movl $len2,$edx,输出如下:

hello,world

after,hello


注意:as86汇编语言中,标号的意思是一个偏移值,而不是地址。

参考文章:

http://www.cnblogs.com/justinzhang/archive/2012/02/20/2360513.html

0 0