Hello, world

    第一篇日志,真还有点儿不知道该写什么好的感觉呢?那就从最简单的开始吧,windows平台下的Hello,world!吧。当然,我写得也不怎么样,希望高手指点!也希望和有相同爱好的朋友交流!
 
comment*-------------------------------------------------------------------
 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.
 
 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.
 
 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
include     windows.inc
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
RegistCls proto :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_szMsg         db                  'Hello, world! Assmbly SDK!', 0
;--------------------------------------------------------------------------
; the code segment
;--------------------------------------------------------------------------

.code
;--------------------------------------------------------------------------
; 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
    invoke  RegisterClassEx, addr wc
    ret
RegistCls endp
;--------------------------------------------------------------------------
; 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
    xor     eax, eax
    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
    .if msg == WM_DESTROY
        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
    xor     eax, eax
    ret
WndProc endp
;--------------------------------------------------------------------------
; implementation of WinMain
;--------------------------------------------------------------------------

WinMain proc hInst:HINSTANCE, hPrev:HINSTANCE, lpCmdLine:LPSTR, nCmdShow:DWORD
    local   msg:MSG
    invoke  RegistCls, hInst
    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
    mov     eax, msg.wParam
    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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值