flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Windows > Win64 example

Author
Thread Post new topic Reply to topic
evk



Joined: 12 Feb 2018
Posts: 4

Win64 example

This is windows 64 bit example below:


Code:
format PE64 GUI 5.0 
entry start 

include 'win64a.inc' 

IDR_MENU = 10 
IDR_DIALOG = 11 

IDM_EXIT = 100 
IDM_ABOUT = 101 

IDLG_BUTTON = 120 

section '.bss' readable writeable 
hWnd dq 0 
hMenu dq        0 

section '.data' data readable writeable 

TitleStr TCHAR 'Win64 program',0 
ClassStr TCHAR 'WIN64DEMO',0 

wc WNDCLASSEX sizeof.WNDCLASSEX,0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE,NULL,ClassStr,NULL 

msg MSG 

section '.text' code readable executable 

start
sub     rsp,8 

invoke  GetModuleHandle,0 

mov     [wc.hInstance],rax 
invoke  LoadIcon,0,IDI_APPLICATION 
mov     [wc.hIcon],rax 
mov     [wc.hIconSm],rax 
invoke  LoadCursor,0,IDC_ARROW 
mov     [wc.hCursor],rax 
invoke  RegisterClassEx,wc 
test    rax,rax 
jz      WIN_START_TERMINATE 

invoke  LoadMenu,[wc.hInstance],IDR_MENU 
mov     [hMenu],rax 

invoke  CreateWindowEx,0,ClassStr,TitleStr,WS_OVERLAPPEDWINDOW,\ 
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,\ 
[hMenu],[wc.hInstance],NULL 
test    rax,rax 
jz      WIN_START_TERMINATE 
mov     [hWnd],rax 

invoke  ShowWindow,[hWnd],SW_SHOWNORMAL 
invoke  UpdateWindow,[hWnd

WIN_START_MSG_LOOP
invoke  GetMessage,msg,NULL,0,0 
cmp     eax,1 
jb      WIN_START_TERMINATE 
jne     WIN_START_MSG_LOOP 
invoke  TranslateMessage,msg 
invoke  DispatchMessage,msg 
jmp     WIN_START_MSG_LOOP 

WIN_START_TERMINATE
invoke  ExitProcess,[msg.wParam

proc WindowProc uses rbx rsi rdihwnd,wmsg,wparam,lparam 

mov     [hwnd],rcx 

cmp     edx,WM_COMMAND 
je      WND_PROC_WM_COMMAND 
cmp     edx,WM_DESTROY 
je      WND_PROC_WM_DESTROY 

invoke  DefWindowProc,rcx,rdx,r8,r9 
jmp     WND_PROC_WM_FINISH 

WND_PROC_WM_COMMAND
mov     ax,r8w 
cmp     ax,IDM_EXIT 
je      WND_PROC_WM_DESTROY 
cmp     ax,IDM_ABOUT 
je      WND_PROC_WM_ABOUT 
jmp     WND_PROC_WM_FINISH 

WND_PROC_WM_ABOUT
invoke  DialogBoxParam,[wc.hInstance],IDR_DIALOG,[hwnd],DialogProc,0 
jmp     WND_PROC_WM_FINISH 

WND_PROC_WM_DESTROY
invoke  PostQuitMessage,0 
xor     eax,eax 

WND_PROC_WM_FINISH
ret 
endp 

proc DialogProc uses rbx rsi rdihwnd,wmsg,wparam,lparam 
local ps:PAINTSTRUCT,rc:RECT,hDC:QWORD 

mov     [hwnd],rcx 

cmp     edx,WM_PAINT 
je      DLG_PROC_PAINT 
cmp     edx,WM_CLOSE 
je      DLG_PROC_CLOSE 
cmp     edx,WM_COMMAND 
je      DLG_PROC_COMMAND 
xor     rax,rax 
jmp     DLG_PROC_FINISH 

DLG_PROC_PAINT
lea     rdx,[ps
invoke  BeginPaint,[hwnd],rdx 
mov     [hDC],rax 
invoke  GetClientRect,[hwnd],addr rc 
invoke  DrawText,[hDC],TitleStr,-1,addr rc,DT_SINGLELINE + DT_CENTER + DT_VCENTER 
invoke  EndPaint,[hwnd],addr ps 
jmp     DLG_PROC_FINISH 

DLG_PROC_COMMAND

DLG_PROC_CLOSE
invoke  EndDialog,rcx,0 
mov     rax,1 

DLG_PROC_FINISH
ret 
endp 

section '.idata' import data readable writeable 

library kernel32,'KERNEL32.DLL',\ 
user32,'USER32.DLL' 

include 'api\kernel32.inc' 
include 'api\user32.inc' 

section '.rsrc' resource data readable 

directory RT_MENU,menus,\ 
RT_DIALOG,dialogs 

resource menus,\ 
IDR_MENU,LANG_ENGLISH+SUBLANG_DEFAULT,main_menu 

resource dialogs,\ 
IDR_DIALOG,LANG_ENGLISH+SUBLANG_DEFAULT,Dialog64 

menu main_menu 
menuitem '&File',0,MFR_POPUP 
menuitem 'E&xit',IDM_EXIT,MFR_END 
menuitem '&Dialog',0,MFR_POPUP + MFR_END 
menuitem '&Dialog',IDM_ABOUT,MFR_END 

dialog Dialog64,'64 bit dialog',50,50,250,100,WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME 
dialogitem 'BUTTON','close',IDLG_BUTTON,200,78,40,14,WS_VISIBLE 
enddialog

Edit by revolution: Added code tags
Post 16 Feb 2018, 13:19
View user's profile Send private message Reply with quote
evk



Joined: 12 Feb 2018
Posts: 4

Win64 example

This is a windows 64bit application example.


Description:
Download
Filename: FasmWin64.zip
Filesize: 2.91 KB
Downloaded: 45 Time(s)

Post 16 Feb 2018, 13:32
View user's profile Send private message Reply with quote
Mikl___



Joined: 30 Dec 2014
Posts: 78


Quote:
This is windows 64 bit example below


evk,
and what's wrong with this windows 64 bit example? This is a question? Is this a fact? You decided to boast that you found an windows 64 bit example?
Post 16 Feb 2018, 13:38
View user's profile Send private message Visit poster's website Reply with quote
evk



Joined: 12 Feb 2018
Posts: 4

I found an article about win64 assembly programming a few years ago. So this is what I wrote after that.
Post 16 Feb 2018, 13:44
View user's profile Send private message Reply with quote
Mikl___



Joined: 30 Dec 2014
Posts: 78

What a tremendous effort to write a few years program that displays a window on the screen
Post 16 Feb 2018, 13:51
View user's profile Send private message Visit poster's website Reply with quote
yeohhs



Joined: 19 Jan 2004
Posts: 168
Location: N 5.43564° E 100.3091°

Thanks for sharing your code, evk. Smile I like the way you created the resources section in fasm syntax. I always have trouble with that.

_________________
“It’s not that we have a short time to live, but that we waste a lot of it.”
-Lucius Annaeus Seneca
Post 16 Feb 2018, 13:52
View user's profile Send private message Visit poster's website Reply with quote
CrawlUp



Joined: 23 May 2017
Posts: 8
Location: the USSR


Mikl___ wrote:
What a tremendous effort to write a few years program that displays a window on the screen



With the introduction of 64 bits of the impression that the assembler has died, I myself have been trying to figure out the driver for a month, but I have not moved beyond the 3 lessons of Four-F.
P.S. Thanks for the link, and for the articles that you wrote.

_________________
Use GoogleTranslate....
Post 16 Feb 2018, 21:08
View user's profile Send private message Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 512

Re: Win64 example


evk wrote:
This is a windows 64bit application example.

Good and clear example to create a basic Window skeleton program. More, more! Very Happy
Post 16 Feb 2018, 22:20
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2018, Tomasz Grysztar.
Powered by rwasa.