format PE GUI 4.0
entry start

include 'win32a.inc'

section '.text' code readable executable

  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
        invoke  GetModuleHandle,0
        mov     [wc.hInstance],eax
        invoke  LoadIcon,0,IDI_APPLICATION
        mov     [wc.hIcon],eax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [wc.hCursor],eax
        invoke  RegisterClass,wc
        invoke  CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_OVERLAPPEDWINDOW+WS_CLIPCHILDREN+WS_CLIPSIBLINGS,16,16,400,200,NULL,NULL,[wc.hInstance],NULL
        mov     [hwnd],eax

  msg_loop:
        invoke  GetMessage,msg,NULL,0,0
        or      eax,eax
        jz      end_loop
        invoke  TranslateMessage,msg
        invoke  DispatchMessage,msg
        jmp     msg_loop

  end_loop:
        invoke  ExitProcess,[msg.wParam]

proc WindowProc hwnd,wmsg,wparam,lparam
        push    ebx esi edi
        cmp     [wmsg],WM_CREATE
        je      .wmcreate
        cmp     [wmsg],WM_SIZE
        je      .wmsize
        cmp     [wmsg],WM_PAINT
        je      .wmpaint
        cmp     [wmsg],WM_KEYDOWN
        je      .wmkeydown
        cmp     [wmsg],WM_DESTROY
        je      .wmdestroy
  .defwndproc:
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     .finish
  .wmcreate:
        invoke  GetDC,[hwnd]
        mov     [hdc],eax
        jmp     .finish
  .wmsize:
        invoke  GetClientRect,[hwnd],rc
        jmp     .finish
  .wmpaint:
        invoke  BeginPaint,[hwnd],ps
        invoke  TextOut, eax, 50, 50, _name, 48
        invoke  EndPaint,[hwnd],ps
        jmp     .finish
  .wmkeydown:
        cmp     [wparam],VK_ESCAPE
        jne     .defwndproc
  .wmdestroy:
        invoke  ReleaseDC,[hwnd],[hdc]
        invoke  PostQuitMessage,0
        xor     eax,eax
  .finish:
        pop     edi esi ebx
        ret
endp

section '.data' data readable writeable

  _title db 'CPU ID',0
  _class db 'CPUID',0
  _name rb 48

  wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,NULL,NULL,_class

  hwnd dd ?
  hdc dd ?
  hrc dd ?

  ps PAINTSTRUCT
  msg MSG
  rc RECT

section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL',\
          user,'USER32.DLL',\
          gdi,'GDI32.DLL'

  import kernel,\
         GetModuleHandle,'GetModuleHandleA',\
         ExitProcess,'ExitProcess'

  import user,\
         RegisterClass,'RegisterClassA',\
         CreateWindowEx,'CreateWindowExA',\
         DefWindowProc,'DefWindowProcA',\
         GetMessage,'GetMessageA',\
         TranslateMessage,'TranslateMessage',\
         DispatchMessage,'DispatchMessageA',\
         LoadCursor,'LoadCursorA',\
         LoadIcon,'LoadIconA',\
         GetClientRect,'GetClientRect',\
         GetDC,'GetDC',\
         ReleaseDC,'ReleaseDC',\
         PostQuitMessage,'PostQuitMessage', \
         BeginPaint, 'BeginPaint',\
         EndPaint, 'EndPaint'

  import gdi,\
         TextOut, 'TextOutA'



