10月 082011
 

helloworld.as:

  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    # 参数一:文件描述符(stdout)
  11.         movl $4, %eax    # 系统调用号(sys_write)
  12.         int  $0x80       # 调用内核功能
  13.         
  14.                          # 退出程序
  15.         movl $0,%ebx     # 参数一:退出代码
  16.         movl $1,%eax     # 系统调用号(sys_exit)
  17.         int  $0x80       # 调用内核功能

# as –gstabs -o helloworld.o helloworld.as
# ld -o helloworld helloworld.o
# ./helloworld                            
Hello, world!

其中:
as ld 都是gcc套件中的程序

常用的汇编开发环境:
masm : 微软开发的 ml.exe , 在visualstudio中都包含了
nasm : http://www.nasm.us/
masm32  : http://www.masm32.com/

参考资料:
强力推荐:http://www.ibm.com/developerworks/cn/linux/l-assembly/
http://www.masm32.com/
http://www.nasm.us/

 Posted by at 上午 8:57