第一篇日志,真还有点儿不知道该写什么好的感觉呢?那就从最简单的开始吧,windows平台下的Hello,world!吧。当然,我写得也不怎么样,希望高手指点!也希望和有相同爱好的朋友交流!
comment*-------------------------------------------------------------------
hello.asm - print the "Hello, world!", first program
hello.asm - print the "Hello, world!", first program
Copyright (c) 2009 by zfwolf <
asmsdk@hotmail.com
>.
This program is free software: you can redistribute it and modify it under
the terms of the GNU General Public License as published by the Free Soft-
ware Foundation, either version 3 of the License, or any later version.
the terms of the GNU General Public License as published by the Free Soft-
ware Foundation, either version 3 of the License, or any later version.
This program is distributed in the hope that it will be useful, but WITH-
OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along
with this program. If not, see < http://www.gnu.org/licenses/ >.
--------------------------------------------------------------------------*
.386
.model flat, stdcall
option casemap:none
with this program. If not, see < http://www.gnu.org/licenses/ >.
--------------------------------------------------------------------------*
.386
.model flat, stdcall
option casemap:none
include windows.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include gdi32.inc
includelib gdi32.lib
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include gdi32.inc
includelib gdi32.lib
;--------------------------------------------------------------------------
; definition of the functions and datas
;--------------------------------------------------------------------------
WinMain proto :DWORD, :DWORD, :DWORD, :DWORD
WndProc proto :DWORD, :DWORD, :DWORD, :DWORD
; definition of the functions and datas
;--------------------------------------------------------------------------
WinMain proto :DWORD, :DWORD, :DWORD, :DWORD
WndProc proto :DWORD, :DWORD, :DWORD, :DWORD
RegistCls proto :DWORD
CreateWnd proto :DWORD, :DWORD
CreateWnd proto :DWORD, :DWORD
.data
g_hInst HINSTANCE ?
g_lpCmdLine LPSTR ?
.const
g_szClsName db 'AsmSdk', 0
g_szWndName db 'Assmbly SDK', 0
g_hInst HINSTANCE ?
g_lpCmdLine LPSTR ?
.const
g_szClsName db 'AsmSdk', 0
g_szWndName db 'Assmbly SDK', 0
g_szMsg db 'Hello, world! Assmbly SDK!', 0
;--------------------------------------------------------------------------
; the code segment
;--------------------------------------------------------------------------
.code
; the code segment
;--------------------------------------------------------------------------
.code
;--------------------------------------------------------------------------
; implementation of RegistCls
;--------------------------------------------------------------------------
RegistCls proc hInst:HINSTANCE
local wc:WNDCLASSEX
; implementation of RegistCls
;--------------------------------------------------------------------------
RegistCls proc hInst:HINSTANCE
local wc:WNDCLASSEX
invoke RtlZeroMemory, addr wc, sizeof WNDCLASSEX
mov wc.cbSize, sizeof WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, offset WndProc
push hInst
pop wc.hInstance
invoke LoadIcon, NULL, IDI_APPLICATION
mov wc.hIcon, eax
invoke LoadCursor, NULL, IDC_ARROW
mov wc.hCursor, eax
invoke GetStockObject, WHITE_BRUSH
mov wc.hbrBackground, eax
mov wc.lpszClassName, offset g_szClsName
mov wc.cbSize, sizeof WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, offset WndProc
push hInst
pop wc.hInstance
invoke LoadIcon, NULL, IDI_APPLICATION
mov wc.hIcon, eax
invoke LoadCursor, NULL, IDC_ARROW
mov wc.hCursor, eax
invoke GetStockObject, WHITE_BRUSH
mov wc.hbrBackground, eax
mov wc.lpszClassName, offset g_szClsName
invoke RegisterClassEx, addr wc
ret
RegistCls endp
ret
RegistCls endp
;--------------------------------------------------------------------------
; implementation of CreateWnd
;--------------------------------------------------------------------------
CreateWnd proc hInst:HINSTANCE, nCmdShow:DWORD
local hwnd:HWND
; implementation of CreateWnd
;--------------------------------------------------------------------------
CreateWnd proc hInst:HINSTANCE, nCmdShow:DWORD
local hwnd:HWND
invoke CreateWindowEx, 0, offset g_szClsName, offset g_szWndName, /
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, /
CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL
mov hwnd, eax
invoke ShowWindow, hwnd, nCmdShow
invoke UpdateWindow, hwnd
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, /
CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL
mov hwnd, eax
invoke ShowWindow, hwnd, nCmdShow
invoke UpdateWindow, hwnd
xor eax, eax
ret
CreateWnd endp
ret
CreateWnd endp
;--------------------------------------------------------------------------
; implementation of WndProc
;--------------------------------------------------------------------------
WndProc proc hwnd:HWND, msg:UINT, wParam:WPARAM, lParam:LPARAM
local hdc:HDC
local rc:RECT
local ps:PAINTSTRUCT
; implementation of WndProc
;--------------------------------------------------------------------------
WndProc proc hwnd:HWND, msg:UINT, wParam:WPARAM, lParam:LPARAM
local hdc:HDC
local rc:RECT
local ps:PAINTSTRUCT
.if msg == WM_DESTROY
invoke PostQuitMessage, 0
.elseif msg == WM_PAINT
invoke BeginPaint, hwnd, addr ps
mov hdc, eax
invoke PostQuitMessage, 0
.elseif msg == WM_PAINT
invoke BeginPaint, hwnd, addr ps
mov hdc, eax
invoke GetClientRect, hwnd, addr rc
invoke DrawText, hdc, offset g_szMsg, -1, addr rc, /
DT_CENTER or DT_SINGLELINE or DT_VCENTER
invoke EndPaint, hwnd, addr ps
.else
invoke DefWindowProc, hwnd, msg, wParam, lParam
ret
.endif
invoke DrawText, hdc, offset g_szMsg, -1, addr rc, /
DT_CENTER or DT_SINGLELINE or DT_VCENTER
invoke EndPaint, hwnd, addr ps
.else
invoke DefWindowProc, hwnd, msg, wParam, lParam
ret
.endif
xor eax, eax
ret
WndProc endp
ret
WndProc endp
;--------------------------------------------------------------------------
; implementation of WinMain
;--------------------------------------------------------------------------
WinMain proc hInst:HINSTANCE, hPrev:HINSTANCE, lpCmdLine:LPSTR, nCmdShow:DWORD
local msg:MSG
; implementation of WinMain
;--------------------------------------------------------------------------
WinMain proc hInst:HINSTANCE, hPrev:HINSTANCE, lpCmdLine:LPSTR, nCmdShow:DWORD
local msg:MSG
invoke RegistCls, hInst
invoke CreateWnd, hInst, nCmdShow
invoke CreateWnd, hInst, nCmdShow
.while TRUE
invoke GetMessage, addr msg, NULL, 0, 0
.break .if eax == 0
invoke TranslateMessage, addr msg
invoke DispatchMessage, addr msg
.endw
invoke GetMessage, addr msg, NULL, 0, 0
.break .if eax == 0
invoke TranslateMessage, addr msg
invoke DispatchMessage, addr msg
.endw
mov eax, msg.wParam
ret
WinMain endp
ret
WinMain endp
;--------------------------------------------------------------------------
; the start of the program
;--------------------------------------------------------------------------
start:
invoke GetModuleHandle, NULL
mov g_hInst, eax
invoke GetCommandLine
mov g_lpCmdLine, eax
invoke WinMain, g_hInst, NULL, g_lpCmdLine, SW_SHOW
invoke ExitProcess, 0
end start
; the start of the program
;--------------------------------------------------------------------------
start:
invoke GetModuleHandle, NULL
mov g_hInst, eax
invoke GetCommandLine
mov g_lpCmdLine, eax
invoke WinMain, g_hInst, NULL, g_lpCmdLine, SW_SHOW
invoke ExitProcess, 0
end start