汇编语言程序范例

来源:互联网 发布:php程序员的自我评价 编辑:程序博客网 时间:2024/06/05 23:07

这个程序主要功能是显示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, %eaxmovl $1, %ebxmovl $output, %ecxmovl $42, %edx#"int $0x80"是系统调用中断 int $0x80movl $1, %eaxmovl $0, %ebxint $0x80

编译

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

执行

./cpuid

输出

The processor Vendor ID is: GenuineIntel

0 0