首页 > 编程语言 > 详细

汇编语言程序范例

时间:2015-06-01 22:48:25      阅读:223      评论:0      收藏:0      [点我收藏+]

这个程序主要功能是显示CPU厂商的Vendor ID

源代码如下:

.section .data

#x是占位符
output:
    .ascii "The processor Vendor ID is: ‘xxxxxxxxxx‘\n"

#_start和output都是标签
.section .text

#如果用gcc编译的话,_start要改为main
.global _start
_start:
    movl $0, %eax
    cpuid

#相当于把字符串output的地址传入到寄存器edi中.
movl $output, %edi

#将调用cpuid命令的内容放入指定的内存
movl %ebx, 28(%edi)
movl %edx, 32(%edi)
movl %ecx, 36(%edi)

#4表示系统调用的值,1表示文件描述符, output是输入的字符
movl $4, %eax
movl $1, %ebx
movl $output, %ecx
movl $42, %edx

#"int $0x80"是系统调用中断 
int $0x80
movl $1, %eax
movl $0, %ebx
int $0x80

编译

as -o cpuid.o assembly_template.s
ld -o cpuid cpuid.o

执行

./cpuid

输出

The processor Vendor ID is: GenuineIntel

汇编语言程序范例

原文:http://blog.csdn.net/csujiangyu/article/details/46314525

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!