News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

My work of asm64

Started by leemarx, April 24, 2009, 02:21:09 AM

Previous topic - Next topic

leemarx

include      windows.inc
include      kernel32.inc
include      user32.inc
include      gdi32.inc
include      string.inc
includelib   kernel32.lib
includelib   user32.lib
includelib   gdi32.lib
;includelib   string.lib

.data
szcln      db   'mycl',0
szcap      db   'Hello !',0
sztxt      db   'Hello World !',0
hWnd      dq   ?
hIn         dq   ?
szRw      db   'RegisterClass faild !',0
szCw      db   'CreateWindow faild !',0
szSw      db   'ShowWindow faild !,',0
szUw      db   'UpdateWindow faild !',0
szloe      db   'List of error description : ',0
szbuf      db   1024 dup(?)
.code
strl      proc   lpszstr
      sub      rsp,28h
      mov   rax,0
      mov   [rsp + 8],rcx
aa:      mov   bl,byte ptr [rcx]
      cmp   bl,0
      jz      exit
      inc      rcx
      inc      rax
      jmp      aa
exit:
      ret
strl      endp
;Callback function for windows
cbf      proc   hw : dq   ,umsg : dd,   wp : dq,   lpa :    dq
      local   ps      :PAINTSTRUCT
      local   hdc      :dq
      local   rc      :RECT
      local   lpbuf   :dq

      mov   [rsp + 20h],r9
      mov   [rsp + 18h],r8
      mov   [rsp + 10h],rdx
      mov   [rsp + 8h],rcx
      
      mov   rbx,rsp
      sub      rsp,28h + 8 * 8
      
      mov   eax,edx
      ;Handle   WM_PAINT message
      cmp   eax,WM_PAINT
      jnz      @f
      ;Get HDC
      lea      rdx,ps
      mov   rcx,[rbx + 8]
      call      BeginPaint
      mov   hdc,rax
      mov   rax,8
      ;format message
      mov   lpbuf,NULL
      mov   rcx,NULL
      mov   [rsp + 30h],rcx
      mov   [rsp + 28h],rcx
      mov   rcx,lpbuf
      mov   [rsp + 20h],rcx
      mov   r9,0
      mov   r8,rax
      mov   rdx,NULL
      mov   rcx,FORMAT_MESSAGE_FROM_SYSTEM or FORMAT_MESSAGE_IGNORE_INSERTS or FORMAT_MESSAGE_ALLOCATE_BUFFER
      call      FormatMessageA
      ;Out put the text
      lea   rcx,szloe
      call      strl
      mov   [rsp + 20h],rax
      lea   r9,szloe
      mov   r8,0
      mov   rdx,0
      mov   rcx,hdc
      call      TextOutA

      ;Finish Paint
      lea      rdx,ps
      mov   rcx,[rbx + 8]
      call      EndPaint
      jmp      exit
@@:
      ;Handle WM_CLOSE message
      cmp   eax,WM_CLOSE
      jnz      @f
      mov   rcx,[rbx + 8]
      call      DestroyWindow
      jmp      exit
      ;Handle   WM_DESTROY
@@:
      cmp   eax,WM_DESTROY
      jnz      @f
      xor      rcx,rcx
      call      PostQuitMessage
      jmp      exit
      ;default message
@@:
def:      
      mov   r9,[rbx + 20h]
      mov   r8,[rbx + 18h]
      mov   rdx,[rbx + 10h]
      mov   rcx,[rbx + 8h]
      call      DefWindowProcA

exit:      ;add      rsp,28h + 8
      ret
cbf      endp
main   proc
      local   wc:WNDCLASSEX
      local   umsg:MSG
      
      sub      rsp,28h + 8 * 9
      ;Get Information about the current CPU
      xor      rax,rax
      cpuid
      ;Fill the buf with CPU Inf

      ;Get modulehandle
      xor      rcx,rcx
      call      GetModuleHandleA
      mov   hIn,rax
      ;Register Class
      mov   wc.cbSize,sizeof WNDCLASSEX
      mov   wc.style,CS_VREDRAW or CS_HREDRAW
      lea      rax,cbf
      mov   wc.lpfnWndProc,rax
      mov   wc.cbClsExtra,0
      mov   wc.cbWndExtra,0
      mov   rax,hIn
      mov   wc.hInstance,rax
      mov   rdx,IDI_APPLICATION
      xor      rcx,rcx
      call      LoadIconA
      mov   wc.hIcon,rax
      mov   wc.hIconSm,rax
      mov   rdx,IDC_ARROW
      xor      rcx,rcx
      call      LoadCursorA
      mov   wc.hCursor,rax
      mov   wc.hbrBackground,COLOR_WINDOW + 1
      mov   wc.lpszMenuName,0
      lea      rax,szcln
      mov   wc.lpszClassName,rax
      lea      rcx,wc
      call      RegisterClassExA
      cmp   rax,0
      jnz      @f
      xor      r9,r9
      lea      r8,szcap
      lea      rdx,szRw
      xor      rcx,rcx
      call      MessageBoxA

@@:
      
      ;CreateWindow
      xor      rax,rax
      mov   [rsp + 58h],rax
      mov   rax,hIn
      mov   [rsp + 50h],rax
      xor      rax,rax
      mov   [rsp + 48h],rax
      mov   [rsp + 40h],rax
      mov   rax,400
      mov   [rsp + 38h],rax
      mov   [rsp + 30h],rax
      mov   rax,CW_USEDEFAULT
      mov   [rsp + 28h],rax
      mov   [rsp + 20h],rax
      mov   r9,WS_OVERLAPPEDWINDOW
      lea      r8,szcap
      lea      rdx,szcln
      xor      rcx,rcx
      call      CreateWindowExA
      mov   hWnd,rax
      cmp   rax,0
      jnz      @f
      xor      r9,r9
      lea      r8,szcap
      lea      rdx,szCw
      xor      rcx,rcx
      call      MessageBoxA
@@:
      ;Show Window
      mov   rdx,SW_SHOW
      mov   rcx,hWnd
      call      Showwindow
      cmp   rax,0
      jnz      @f
      xor      r9,r9
      lea      r8,szcap
      lea      rdx,szSw
      xor      rcx,rcx
      call      MessageBoxA
@@:
      mov   rcx,hWnd
      call      UpdateWindow
      cmp   rax,0
      jnz      @f
      xor      r9,r9
      lea      r8,szcap
      lea      rdx,szUw
      xor      rcx,rcx
      call      MessageBoxA
      ;jmp      exit
      ;Message loop
@@:
      xor      r9d,r9d
      xor      r8d,r8d
      mov   rdx,NULL
      lea      rcx,umsg
      call      GetMessageA
      cmp   rax,0
      jz      ex
      lea      rcx,umsg
      call      TranslateMessage
      lea      rcx,umsg
      call      DispatchMessageA
      jmp      @b
      
ex:
      
      xor      r9,r9
      lea      r8,szcap
      lea      rdx,sztxt
      xor      rcx,rcx
      call      MessageBoxA
      xor      rcx,rcx
      call      ExitProcess
      ;add      rsp,28h + 8 * 12
      ret
main   endp
      end