第一个版本

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

 

(责任编辑:A6)

本站文章仅代表作者观点,本站仅传递信息,并不表示赞同或反对.转载本站点内容时请注明来自-Linux伊甸园。如不注明,将根据《互联网著作权行政保护办法》追究其相应法律责任。

--------------------next---------------------