Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1754951
  • 博文数量: 413
  • 博客积分: 8399
  • 博客等级: 中将
  • 技术积分: 4325
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-09 10:44
文章分类

全部博文(413)

文章存档

2015年(1)

2014年(18)

2013年(39)

2012年(163)

2011年(192)

分类: LINUX

2011-09-21 18:55:12


下面的代码是摘录自网络。
  1. #cpuid.s Sample program to extract the processor Vendor ID
  2. .section .data
  3.        output:
  4.          .ascii "The processor Vendor ID is 'xxxxxxxxxxxx'\n"
  5. .section .text
  6. .global _start
  7. _start:

  8. movl $0, %eax
  9. cpuid
  10. movl $output, %edi
  11. movl %ebx, 28(%edi) #将cpuid指令的结果保存到$output的相应位置中
  12. movl %edx, 32(%edi)
  13. movl %ecx, 36(%edi)
  14. movl $4, %eax       # write的系统调用号
  15. movl $1, %ebx       # stdout = 1, write的第1个参数
  16. movl $output, %ecx  # write的第2个参数,字符串的地址
  17. movl $42, %edx      # write的第3个参数,即输出字符串的长度
  18. int $0x80
  19. movl $1, %eax       # exit的系统调用号
  20. movl $0, %ebx       # exit的参数0
  21. int $0x80          
编译、执行及结果:
digdeep@ubuntu:~/assembly$ as -o cpuid.o cpuid.s
digdeep@ubuntu:~/assembly$ ld -o cpuid cpuid.o
digdeep@ubuntu:~/assembly$ ./cpuid
The processor Vendor ID is 'GenuineIntel'
                           
阅读(2051) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~