Article title: knowledge popularization of Linux release edition: CPUID of three versions. Linux is a technology channel of the IT lab in China. Includes desktop applications, Linux system management, kernel research, embedded systems, open source, and other basic classification First version
X86-ubuntu-64 bit environment, at&t format (gas Assembly), called using linux:
#cpuid.s show extract the processor vendor ID.section .dataoutput:.ascii "the processor vendor ID is 'XXXXXXXXXXXX'\n".section .text.globl mainmain: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, %eaxmovl $0, %ebxint $0x80
|
Version 2
X86-ubuntu-64 bit environment, at&t format (gas Assembly), using C library functions, pay attention to the use of 64-bit registers, want to change to 32-bit as long as all with r into with e can be
# Cpuidinlib. s show extract the processor vendor ID using library. section. dataoutput :. asciz "the processor vendor ID is % s \ n ". section. bss. lcomm buffer, 12. section. text. globl _ start_start: movq $0, % raxcpuidmovq $ buffer, % rdimovl % ebx, (% rdi) movl % edx, 4 (% rdi) movl % ecx, 8 (% rdi) movq $ output, % rdimovq $ buffer, % rsixorq % rax, % raxcall printfmovq $0, % rdixorq % rax, % raxcall exit, but there is a problem with printf ("% s ", str );
|
This form is not common. since it is a string, str should end with 0, but note that the above is not ended with 0, how does printf determine that the string is ended? I have succeeded in C, but I don't know why. tell me what I know.
The third x86-win32, using intel syntax (masm32), calling windows API. This estimation is familiar
; Cpuid.686.model flat, stdcalloption casemap: noneinclude windows. incinclude user32.incincludelib user32.libinclude kernel32.incincludelib kernel32.libincludelib msvcrt. libsprintf proto c: DWORD,: DWORD,: VARARG. datamsg db 'The processor vendor ID is % s', 0 note db' note ', 0. data? Result db 13 dup (?) Buff db 128 dup (?). Codestart: call goinvoke ExitProcess, NULLgo: mov eax, 0 cpuidmov edi, offset resultmov [edi], ebxmov 4 [edi], edxmov 8 [edi], ecxmov byte ptr 12 [edi], 0 push dword ptr offset resultpush dword ptr offset msgpush dword ptr offset buff; call sprintf mov eax, 77c0f931Hcall eaxadd esp, 12 invoke MessageBox, NULL, addr buff, addr note, MB_OKretend start
|