Linux中国 Linux中国门户站!
设为主页 设为主页
收藏本站 收藏本站
 
当前位置 :首页 ->Linux技术 ->网络应用 ->正文

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

来源: 作者:Webmaster 时间:2008-02-04 点击: [收藏] [投稿]

第一个版本

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

(责任编辑:云子)



 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<



上一篇:新手学堂:升级Linux内核的一般步骤方法   下一篇:关于Linux操作系统下软件开发工具的选择

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论
更多相关文章
Power by linux-cn.com 粤ICP备05006655号