我的第一个汇编程序-Hello,World!

作为一个程序员,我想起码要精通3们语言:C, C++, 汇编!今天我开始了我的奇妙的汇编世界。。。。。

我用的是GNU  assembler(GAS).

现用VIM创建一个hello.s文件:

[root@localhost ~]# vim hello.s
回车后,编写汇编代码如下:

  1 .data
  2     msg : .string "Hello, World!/n"
  3     len = . -msg
  4 .text
  5 .global _start
  6
  7 _start:
  8     movl $len, %edx
  9     movl $msg, %ecx
 10     movl $1, %ebx
 11     movl $4, %eax
 12     int  $0x80
 13
 14     movl $0, %ebx
 15     movl $1, %eax
 16     int  $0x80

哈哈。。一个汇编代码就这么搞定了(真长!要是用它来写个操作系统估计要绕地球好多圈吧!)

 

下面开始编译:

 

[root@localhost ~]# as hello.s -o hello.o
[root@localhost ~]# ld -s -o hello hello.o

OK!在当前目录下就产生了一个hello可执行文件。

 

执行:

 

[root@localhost ~]# ./hello
Hello, World!

 

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值