今天学习了以下linux下的nasm汇编语言,贴出源码以便自己以后回忆
功能:
获取CPU信息
源码文件 :cpuid.s
.section .data
output:
.ascii "The processor Vendor ID is 'xxxxxxxxxxxx'\n"
.section .text
.globl _start
_start:
nop
movl $0, %eax
cpuid
movl $output, %edi
movl %ebx, 28(%edi)
movl %edx, 32(%edi)
movl %ecx, 36(%edi)
movl $4, %eax
movl $1, %ebx
movl $output, %ecx
movl $43, %edx
int $0x80
movl $1, %eax
movl $0, %ebx
int $0x80
编译(带调试信息):
as -gstabs -o cpuid.o cpuid.s
链接:
ld -o cpuid cpuid.o
执行:
./cpuid
执行结果
The processor Vendor ID is 'GenuineIntel'
Linux85fan 于 2007-12-16 17:08:15发表:
项,还没用过汇编,以后学习。。