cpuid 的使用方法

.section .data
output:
   .ascii "the processor vendor id is 'XXXXXXXXXXXX'\n"
.section .text
.globl _start
_start:
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 $42,%edx
int $0x80
movl $1,%eax;
movl $0,%ebx
int $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, %eax
cpuid
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, %edi
movl %ebx, 28(%edi)
movl %edx, 32(%edi)
movl %ecx, 36(%edi)

movl $4,%eax
movl $1,%ebx
movl $output,%ecx
movl $42,%edx
int $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,%ebx
int $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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Farmwang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值