cpuid 的使用方法

来源:互联网 发布:剑灵天女捏脸图文数据 编辑:程序博客网 时间:2024/06/06 01:03
.section .dataoutput:   .ascii "the processor vendor id is 'XXXXXXXXXXXX'\n".section .text.globl _start_start:movl $0,%eaxcpuidmovl $output,%edimovl %ebx,28(%edi)movl %edx,32(%edi)movl %ecx,36(%edi)movl $4,%eaxmovl $1,%ebxmovl $output,%ecxmovl $42,%edxint $0x80movl $1,%eax;movl $0,%ebxint $0x80

1:.ascii 

The .ascii declarative is used to declare a text string using ASCII characters. 

The string elements are: predefined and placed in memory, with the starting memory location denoted by the label output. 

The x’s are used as placeholders in the memory area reserved for the data variable.

 When the vendor ID string is extracted from the processor, it will be placed in the data at those memory locations

2:cpuid

movl $0, %eaxcpuid
The zero value in EAX defines the CPUID output option (the Vendor ID string in this case).

 cpuid 的使用方法

cpuid 指令由 eax 寄存器获得输入,执行 cpuid 指令前,将功能号传给 eax 寄存器:

输入:

  • eax

输出:

  • eax:最大的基本功能号
  • ebx:"Genu"
  • edx: "ineI"
  • ecx:"ntel"
movl $output, %edimovl %ebx, 28(%edi)movl %edx, 32(%edi)movl %ecx, 36(%edi)

movl $4,%eaxmovl $1,%ebxmovl $output,%ecxmovl $42,%edxint $0x80
1:This program uses a Linux system call (int $0x80) to access the console display from the Linux kernel。
2:To access these kernel functions, you must use the int instruction code, which generates a software:interrupt, with a value of 0x80.
3: The specific function that is performed is determined by the value of the EAX register.
❑ EAX contains the system call value.
❑ EBX contains the file descriptor to write to.
❑ ECX contains the start of the string.
❑ EDX contains the length of the string.

movl $1,%eax;movl $0,%ebxint $0x80

1:By using system call 1 (the exit function), the program is properly terminated, and returns to the command prompt. 
2:The EBX register contains the exit code value returned by the program to the shell. 

This can be used to produce different results in a shell script program, depending on situations within the assembly language program. 
A value of zero indicates the program executed successfully.

原创粉丝点击