64 bit assembler > Mikl__'s ml64 examples
Examples for Win64 Iczelion tutorial
Mikl__:
Attention!The programs were written and tested in Windows Seven pro, how the programs will work in Windows eight I don't know
Win x64 Tutorial #2: MessageBox
--- Code: ---OPTION DOTNAME
option casemap:none
include temphls.inc
include win64.inc
include kernel32.inc
include user32.inc
includelib kernel32.lib
includelib user32.lib
OPTION PROLOGUE:rbpFramePrologue
.code
WinMain proc
sub rsp,5*8
invoke MessageBox,NULL,&MsgBoxText,&MsgCaption,MB_OK
invoke ExitProcess,NULL
WinMain endp
MsgCaption db "Iczelion's tutorial #2",0
MsgBoxText db "Win64 Assembly is Great!",0
end
--- End code ---
bat-file
--- Code: ---cls
set masm64_path=\masm64\
set filename=%1
if exist %1.rc (
%masm64_path%bin\RC /r %filename%.rc || exit
%masm64_path%bin\cvtres /machine:X64 %filename%.res || exit
%masm64_path%bin\ml64 /Cp /c /I"%masm64_path%Include" %filename%.asm || exit
%masm64_path%bin\link /SUBSYSTEM:WINDOWS /LIBPATH:"%masm64_path%Lib" ^
/entry:WinMain %filename%.obj %filename%.res /LARGEADDRESSAWARE:NO ^
/ALIGN:16 /SECTION:.text,W ^
/BASE:0x400000 /STUB:%masm64_path%\bin\stubby.exe || exit
del %filename%.obj
del %filename%.res
) else (
%masm64_path%bin\ml64 /Cp /c /I"%masm64_path%Include" %filename%.asm || exit
%masm64_path%bin\link /SUBSYSTEM:WINDOWS /LIBPATH:"%masm64_path%Lib" ^
/entry:WinMain %filename%.obj /LARGEADDRESSAWARE:NO ^
/ALIGN:16 /SECTION:.text,W ^
/BASE:0x400000 /STUB:%masm64_path%\bin\stubby.exe || exit
del %filename%.obj
)
--- End code ---
Win x64 Tutorial #2a: MessageBox
--- Code: ---OPTION DOTNAME
option casemap:none
include temphls.inc
include win64.inc
include user32.inc
includelib user32.lib
OPTION PROLOGUE:rbpFramePrologue
.code
WinMain proc
enter 4*8,0
xor ecx,ecx
mov r9,rcx
lea r8,MsgCaption
lea edx,MsgBoxText
call MessageBox
leave
ret
WinMain endp
MsgCaption db "Iczelion's tutorial #2a",0
MsgBoxText db "Win64 Assembly is Great!",0
end
--- End code ---
Win x64 Tutorial #2b: MessageBox
--- Code: ---OPTION DOTNAME
option casemap:none
include temphls.inc
include win64.inc
include kernel32.inc
include user32.inc
includelib kernel32.lib
includelib user32.lib
OPTION PROLOGUE:rbpFramePrologue
.code
WinMain proc
push rbp
mov rbp,rsp
sub rsp,30h
invoke GetModuleHandle,NULL
mov x1,rax
invoke LoadIcon,NULL,IDI_APPLICATION
mov x2,rax
invoke LoadCursor,NULL,IDC_ARROW
mov x3,rax
mov rax,x1
mov [rsp+20h],eax
lea ecx,buffer
lea edx,fmt
mov r8,x3
mov r9,x2
call wsprintf
invoke MessageBox,NULL,&buffer,&MsgCaption,MB_OK
invoke ExitProcess,NULL
WinMain endp
MsgCaption db "Iczelion's tutorial #2b",0
fmt db "hCursor = %08Xh",0Ah,"hIcon = %08Xh",0Ah,"hInstance =%08Xh",0
n = $ - fmt + 12
buffer db n dup(?)
x1 dq ?
x2 dq ?
x3 dq ?
end
--- End code ---
Mikl__:
Win x64 Tutorial #3: A Simple Window
--- Code: ---include win64a.inc
.code
WinMain proc
local msg:MSG
push rbp
mov ebp,esp
sub esp,sizeof MSG
xor ebx,ebx
mov eax,10029h
push rax ;hIconSm
mov edi,offset ClassName
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_WINDOWTEXT;hbrBackground
push 10005h ;hCursor
push rax ;hIcon
mov esi,400000h
push rsi ;hInstance
push rbx ;cbClsExtra & cbWndExtra
mov eax,offset WndProc
push rax ;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
mov rcx,rsp ;addr WNDCLASSEX
call RegisterClassEx
push rbx
push rsi ;rsi=400000h
shl esi,9 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push rsi
push rsi
push rsi
push rsi
mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
xor ecx,ecx
sub esp,20h
call CreateWindowEx
@@: lea ecx,msg
xor edx,edx
xor r8d,r8d
xor r9d,r9d
call GetMessage
lea ecx,msg
call DispatchMessage
jmp @b
WinMain endp
WndProc:cmp edx,WM_DESTROY
je wmDESTROY
jmp DefWindowProc
wmDESTROY: xor ecx,ecx
call ExitProcess
;---------------------------------------
ClassName db 'Win64 Iczelion lesson #3',0
end
--- End code ---
* call fuctions GetModuleHandle, LoadIcon, LoadCursor is unnecessary, they always return the same number, you can see the debugger in advance or in "Tutorial 2b: MessageBox"
* instead PostQuitMessage directly use ExitProcess it will simplify the message loop
Mikl__:
Win x64 Tutorial #4: Painting with Text
--- Code: ---OPTION DOTNAME
option casemap:none
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
OPTION PROLOGUE:rbpFramePrologue
OPTION EPILOGUE:rbpFrameEpilogue
.code
WinMain proc
msg equ [rbp-sizeof MSG]
enter sizeof MSG+sizeof WNDCLASSEX+20h,0
xor ebx,ebx
push 10029h ;hIconSm
lea rdi,ClassName
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_WINDOW;hbrBackground
push 10005h ;hCursor
push 10029h ;hIcon
mov esi,400000h
push rsi ;hInstance
push rbx ;cbClsExtra & cbWndExtra
lea rax,WndProc
push rax ;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
mov rcx,rsp ;addr WNDCLASSEX
push rbx
push rbx
push rbx
push rbx
call RegisterClassEx
add rsp,sizeof WNDCLASSEX+20h
push rbx
push rsi ;rsi=400000h
shl esi,9 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push rsi
push rsi
push rsi
push rsi
mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
xor ecx,ecx
push rbx
push rbx
push rbx
push rbx
call CreateWindowEx
lea edi,msg
@@: mov ecx,edi
xor edx,edx
mov r8,rbx
mov r9,rbx
call GetMessage
mov ecx,edi
call DispatchMessage
jmp @b
WinMain endp
WndProc:
hwnd equ [rbp+10h]
ps equ [rbp-sizeof PAINTSTRUCT]
expRect equ ps-sizeof RECT
enter sizeof PAINTSTRUCT+sizeof RECT+28h,0
mov hwnd,rcx
cmp edx,WM_DESTROY
je wmDESTROY
cmp edx,WM_PAINT
je wmPAINT
cmp edx,WM_SIZE
je wmPAINT
leave
jmp DefWindowProc
wmDESTROY: xor ecx,ecx
call ExitProcess
wmSIZE: mov r8d,1
xor edx,edx
call InvalidateRect;send WM_PAINT if size changes
jmp wmBYE
wmPAINT: lea edx,ps
call BeginPaint
mov rcx,hwnd
lea rdx,expRect
call GetClientRect
mov qword ptr [rbp-60h],DT_SINGLELINE or DT_CENTER or DT_VCENTER
lea r9,expRect
or r8,-1
lea edx,expTxt
mov rcx,ps.PAINTSTRUCT.hdc
call DrawText
lea edx,ps
mov rcx,hwnd
call EndPaint
wmBYE: leave
retn
;---------------------------------------
ClassName db 'Win64 Iczelion''s lesson #4: Painting with Text',0
expTxt db 'Win64 assembly with MASM is great and easy',0
end
--- End code ---
Mikl__:
Win x64 Tutorial #5: More about Text
--- Code: ---OPTION DOTNAME
option casemap:none
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include gdi32.inc
includelib gdi32.lib
OPTION PROLOGUE:rbpFramePrologue
OPTION EPILOGUE:rbpFrameEpilogue
.code
WinMain proc
msg equ [rbp-sizeof MSG]
enter sizeof MSG+sizeof WNDCLASSEX+20h,0
xor ebx,ebx
push 10029h ;hIconSm
lea rdi,ClassName
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_WINDOW;hbrBackground
push 10005h ;hCursor
push 10029h ;hIcon
mov esi,400000h
push rsi ;hInstance
push rbx ;cbClsExtra & cbWndExtra
lea rax,WndProc
push rax ;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
mov rcx,rsp ;addr WNDCLASSEX
push rbx
push rbx
push rbx
push rbx
call RegisterClassEx
add rsp,sizeof WNDCLASSEX+20h
push rbx
push rsi ;rsi=400000h
shl esi,9 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push rsi
push rsi
push rsi
push rsi
mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
xor ecx,ecx
push rbx
push rbx
push rbx
push rbx
call CreateWindowEx
lea edi,msg
@@: mov ecx,edi
xor edx,edx
mov r8,rbx
mov r9,rbx
call GetMessage
mov ecx,edi
call DispatchMessage
jmp @b
WinMain endp
WndProc:
hwnd equ [rbp+10h]
ps equ [rbp-sizeof PAINTSTRUCT]
enter sizeof PAINTSTRUCT+98h,0
mov hwnd,rcx
cmp edx,WM_DESTROY
je wmDESTROY
cmp edx,WM_PAINT
je wmPAINT
leave
jmp DefWindowProc
wmDESTROY: xor ecx,ecx
call ExitProcess
wmPAINT: lea edx,ps
call BeginPaint
mov edx,OBJ_FONT
mov rcx,ps.PAINTSTRUCT.hdc
call GetCurrentObject
push rax ;default font object
lea rax,expFont
push rax
push DEFAULT_PITCH or FF_SCRIPT
push rbx;DEFAULT_QUALITY
push rbx;CLIP_DEFAULT_PRECIS
push rbx;OUT_DEFAULT_PRECIS
push OEM_CHARSET
push rbx
push rbx
push rbx
push 400
mov r9,rbx
mov r8,rbx
mov edx,12
mov ecx,26
push rbx
push rbx
push rbx
push rbx
call CreateFont
mov rdx,rax
mov rcx,ps.PAINTSTRUCT.hdc
call SelectObject
mov edx,32C8C8h
mov rcx,ps.PAINTSTRUCT.hdc
call SetTextColor
mov edx,0FF0000h
mov rcx,ps.PAINTSTRUCT.hdc
call SetBkColor
lea ecx,expTxt
call lstrlen ;help us to count the string length
push rax
lea r9,expTxt
xor edx,edx
mov r8,rdx
mov rcx,ps.PAINTSTRUCT.hdc
push rbx
push rbx
push rbx
push rbx
call TextOut
add rsp,30h
pop rdx
mov rcx,ps.PAINTSTRUCT.hdc
call SelectObject
lea edx,ps
mov rcx,hwnd
call EndPaint
wmBYE: leave
retn
;---------------------------------------
ClassName db 'Win64 Iczelion''s lesson #5:More about Text',0
expTxt db 'Win64 assembly with MASM is great and easy',0
expFont db 'script',0
end
--- End code ---
Mikl__:
Win x64 Tutorial #6: Keyboard Input
--- Code: ---OPTION DOTNAME
option casemap:none
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include gdi32.inc
includelib gdi32.lib
OPTION PROLOGUE:rbpFramePrologue
OPTION EPILOGUE:rbpFrameEpilogue
.code
WinMain proc
msg equ [rbp-sizeof MSG]
enter sizeof MSG+sizeof WNDCLASSEX+20h,0;90h,0
xor ebx,ebx
push 10029h ;hIconSm
lea rdi,ClassName
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_WINDOW;hbrBackground
push 10005h ;hCursor
push 10029h ;hIcon
mov esi,400000h
push rsi ;hInstance
push rbx ;cbClsExtra & cbWndExtra
lea rax,WndProc
push rax ;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
mov rcx,rsp ;addr WNDCLASSEX
push rbx
push rbx
push rbx
push rbx
call RegisterClassEx
add rsp,sizeof WNDCLASSEX+20h
push rbx
push rsi ;rsi=400000h
shl esi,9 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push 352
push 512
push rsi
push rsi
mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
xor ecx,ecx
push rbx
push rbx
push rbx
push rbx
call CreateWindowEx
lea edi,msg
@@: mov ecx,edi
xor edx,edx
mov r8,rbx
mov r9,rbx
call GetMessage
mov ecx,edi
call TranslateMessage
mov ecx,edi
call DispatchMessage
jmp @b
WinMain endp
WndProc:
hwnd equ [rbp+10h]
ps equ [rbp-sizeof PAINTSTRUCT]
enter sizeof PAINTSTRUCT+20h,0
mov hwnd,rcx
cmp edx,WM_DESTROY
je wmDESTROY
cmp edx,WM_CHAR
je wmCHAR
cmp edx,WM_PAINT
je wmPAINT
leave
jmp DefWindowProc
wmDESTROY: xor ecx,ecx
call ExitProcess
wmCHAR: mov expChar,r8
mov r8d,TRUE
xor edx,edx
call InvalidateRect
jmp wmBYE
wmPAINT: lea edx,ps
call BeginPaint
sub rsp,10h
mov qword ptr [rsp+20h],lengthof Message
lea r9,Message
mov r8d,90
mov edx,192
mov rcx,ps.PAINTSTRUCT.hdc
call TextOut
mov qword ptr [rsp+20h],1
lea r9,expChar
mov r8d,150
mov edx,242
mov rcx,ps.PAINTSTRUCT.hdc
call TextOut
add rsp,10h
lea edx,ps
mov rcx,hwnd
call EndPaint
wmBYE: leave
retn
;---------------------------------------
ClassName db 'Win64 Iczelion''s lesson #6: Keyboard Input',0
Message db 'Press any key'
expChar dq '?'
end
--- End code ---
Navigation
[0] Message Index
[#] Next page
Go to full version