Linux发行版知识普及:三个版本的CPUID

王朝system·作者佚名  2008-05-21
宽屏版  字体: |||超大  

第一个版本

x86-ubuntu-64位环境,at&t格式(gas汇编),使用linux系统调用:

#cpuid.s show extract the processor vendor ID

.section .data

output:

.ascii "the processor vendor ID is 'XXXXXXXXXXXX'\n"

.section .text

.globl main

main:

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

第二个版本

x86-ubuntu-64位环境,at&t格式(gas汇编),使用C库函数,注意使用了64位寄存器,想改成32位只要把所有带r的改成带e的就可以了

# cpuidinlib.s show extract the processor vendor ID using library

.section .data

output:

.asciz "the processor vendor ID is %s\n"

.section .bss

.lcomm buffer, 12

.section .text

.globl _start

_start:

movq $0, %rax

cpuid

movq $buffer, %rdi

movl %ebx, (%rdi)

movl %edx, 4(%rdi)

movl %ecx, 8(%rdi)

movq $output, %rdi

movq $buffer, %rsi

xorq %rax, %rax

call printf

movq $0, %rdi

xorq %rax, %rax

call exit

不过上面有一个问题

printf("%s", str);

这样的形式不常见,既然是字符串, str应该是以0结束的,但是注意上面并没有以0结束,那么printf是怎么判断字符串结束了呢? 在C下一样成功,不知道为什么,知道的告诉我下。

第三个 x86-win32,使用intel语法(masm32开发包), 调用windows API.这个估计都熟悉

;; cpuid

.686

.model flat, stdcall

option casemap: none

include windows.inc

include user32.inc

includelib user32.lib

include kernel32.inc

includelib kernel32.lib

includelib msvcrt.lib

sprintf PROTO C:DWORD, :DWORD, :VARARG

.data

msg db 'the processor vendor ID is %s', 0

note db '注意', 0

.data?

result db 13 dup(?)

buff db 128 dup(?)

.code

start:

call go

invoke ExitProcess,NULL

go:

mov eax, 0

cpuid

mov edi, offset result

mov [edi], ebx

mov 4[edi], edx

mov 8[edi], ecx

mov byte ptr 12[edi], 0

push dword ptr offset result

push dword ptr offset msg

push dword ptr offset buff

;call sprintf

mov eax, 77c0f931H

call eax

add esp, 12

invoke MessageBox, NULL, addr buff, addr note, MB_OK

ret

end start

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有