flat assembler
Message board for the users of flat assembler.
Index
> Windows > [Tutorial] Display processor name |
Author |
|
FlierMate 18 Apr 2021, 18:16
Here's a shorter version, but I believe there is better way....like reverse bits?
Code: ; Processor Name v2 ; ; CPUNAME.ASM ; Copyright (C) 2021 Boo Khan Ming ; ; MIT license apply ; format PE GUI 4.0 entry start include 'win32a.inc' section '.data' readable writable _caption db 'Processor Name',0 _counter dd ? _func dd 80000002h section '.code' code readable writable executable _name rb 48 _null db 0 start: mov dword [_counter],0 .loop: mov eax, dword [_func] cpuid push ecx mov ecx, dword [_counter] mov byte [_name + ecx + 0],al mov byte [_name + ecx + 1],ah shr eax,16 mov byte [_name + ecx + 2],al mov byte [_name + ecx + 3],ah mov byte [_name + ecx + 4],bl mov byte [_name + ecx + 5],bh shr ebx,16 mov byte [_name + ecx + 6],bl mov byte [_name + ecx + 7],bh pop ecx mov eax, dword [_counter] mov byte [_name + eax + 8],cl mov byte [_name + eax + 9],ch shr ecx,16 mov byte [_name + eax + 10],cl mov byte [_name + eax + 11],ch mov byte [_name + eax + 12],dl mov byte [_name + eax + 13],dh shr edx,16 mov byte [_name + eax + 14],dl mov byte [_name + eax + 15],dh add dword [_func],1 cmp dword [_func], 80000005h je .show add dword [_counter],16 jmp .loop .show: push 0x40 push _caption push _name push 0 call [MessageBox] push 0 call [ExitProcess] section '.idata' import readable writable library kernel,'KERNEL32.DLL',\ user,'USER32.DLL' import kernel,\ ExitProcess,'ExitProcess' import user,\ MessageBox,'MessageBoxA' |
|||
18 Apr 2021, 18:16 |
|
revolution 18 Apr 2021, 18:26
Did you know that x86 CPUs are little endian?
Perhaps that information can help you to make the code more compact. |
|||
18 Apr 2021, 18:26 |
|
FlierMate 18 Apr 2021, 18:49
revolution wrote: Did you know that x86 CPUs are little endian? Thanks for the great tip, finally.... Code: ; Processor Name v3 ; ; CPUNAME.ASM ; Copyright (C) 2021 Boo Khan Ming ; ; MIT license apply ; format PE GUI 4.0 entry start include 'win32a.inc' section '.data' readable writable _caption db 'Processor Name',0 section '.code' code readable writable executable _name rb 48 start: mov eax, 0x80000002 cpuid mov dword [_name], eax mov dword [_name + 4], ebx mov dword [_name + 8], ecx mov dword [_name + 12], edx mov eax, 0x80000003 cpuid mov dword [_name + 16], eax mov dword [_name + 20], ebx mov dword [_name + 24], ecx mov dword [_name + 28], edx mov eax, 0x80000004 cpuid mov dword [_name + 32], eax mov dword [_name + 36], ebx mov dword [_name + 40], ecx mov dword [_name + 44], edx push 0x40 push _caption push _name push 0 call [MessageBox] push 0 call [ExitProcess] section '.idata' import readable writable library kernel,'KERNEL32.DLL',\ user,'USER32.DLL' import kernel,\ ExitProcess,'ExitProcess' import user,\ MessageBox,'MessageBoxA' I appreciate that info, @revolution. Last edited by FlierMate on 18 Apr 2021, 18:58; edited 1 time in total |
|||
18 Apr 2021, 18:49 |
|
revolution 18 Apr 2021, 18:57
Looks good.
|
|||
18 Apr 2021, 18:57 |
|
FlierMate 16 Oct 2021, 14:57
And this is the same code, but for Linux x64.
Code: format ELF64 executable 3 segment readable executable entry $ mov eax, 0x80000002 cpuid mov dword [cpu], eax mov dword [cpu + 4], ebx mov dword [cpu + 8], ecx mov dword [cpu + 12], edx mov eax, 0x80000003 cpuid mov dword [cpu + 16], eax mov dword [cpu + 20], ebx mov dword [cpu + 24], ecx mov dword [cpu + 28], edx mov eax, 0x80000004 cpuid mov dword [cpu + 32], eax mov dword [cpu + 36], ebx mov dword [cpu + 40], ecx mov dword [cpu + 44], edx mov byte [cpu + 48],0xA ;Append line feed mov edx,49 lea rsi,[cpu] mov edi,1 ; STDOUT mov eax,1 ; sys_write syscall xor edi,edi ; exit code 0 mov eax,60 ; sys_exit syscall segment readable writeable cpu rb 49 |
|||
16 Oct 2021, 14:57 |
|
macomics 17 Oct 2021, 10:15
Code: stosd xchg eax, ebx stosd xchg eax, ecx stosd xchg eax, edx stosd |
|||
17 Oct 2021, 10:15 |
|
FlierMate 17 Oct 2021, 12:18
macomics wrote:
Clever trick, it reduced my binary file size from 302 to 239 bytes. New code as below: Code: format ELF64 executable 3 segment readable writeable executable cpu rb 49 entry $ mov eax, 0x80000002 lea edi,[cpu] @@: push rax cpuid stosd xchg eax,ebx stosd xchg eax,ecx stosd xchg eax,edx stosd pop rax inc eax cmp ax,5 jnz @b mov byte [cpu + 48],0xA ;Append line feed mov edx,49 lea rsi,[cpu] mov edi,1 ; STDOUT mov eax,1 ; sys_write syscall xor edi,edi ; exit code 0 mov eax,60 ; sys_exit syscall I just learned how to use "@@" and "@b". Thank you. |
|||
17 Oct 2021, 12:18 |
|
macomics 17 Oct 2021, 13:22
FlierMate wrote:
Code: lea rdi, [cpu] push rdi @@: ... cmp al, 5 ... pop rsi mov byte [rdi], 0xa push 1 sub rdi, rsi pop rax lea edx, [edi+1] mov edi, eax syscall |
|||
17 Oct 2021, 13:22 |
|
FlierMate1 04 Jun 2022, 09:21
Example output in Windows 11:
|
||||||||||
04 Jun 2022, 09:21 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.