模仿win32的Hello,World程序: .386.modelflat,stdcalloptioncasemap:none;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;Include文件定义;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>includewindows.incincludegdi32.incincludelibgdi32.libincludeuser32.incincludelibuser32.libincludekernel32.incincludelibkernel32.lib;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;数据段;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.data?hInstancedd?;应用程序句柄hWinMaindd?;窗口句柄.constszClassNamedb'MyClass',0;窗口类名称szCaptionMaindb'MyfirstWindow!',0;窗口标题szTextdb'Hello,Win32Assembly!!',0;要显示的信息szButtondb'button',0szButtonTextdb'点我吧!!',0szMsgTitledb'信息',0szErrorMsgdb'出错啦!!',0;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;代码段;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.code;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;出错处理过程;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>_ErrorProcprocinvokeMessageBox,NULL,offsetszErrorMsg,offsetszMsgTitle,MB_OKret_ErrorProcendp;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;窗口过程;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>_ProcWinMainprocusesebxediesihWnd,uMsg,wParam,lParam;让汇编器保持子程序中使用到的寄存器的正确性local@stPs:PAINTSTRUCTlocal@stRect:RECTlocal@hDcmoveax,uMsg;********************************************************************.ifeax==WM_CREATEinvokeCreateWindowEx,NULL,offsetszButton,offsetszButtonText,/WS_CHILDorWS_VISIBLE,100,100,65,50,hWnd,1,hInstance,NULL;********************************************************************.elseifeax==WM_PAINTinvokeBeginPaint,hWnd,addr@stPsmov@hDc,eaxinvokeGetClientRect,hWnd,addr@stRectinvokeDrawText,@hDc,addrszText,-1,/;长度设置为-1,表示输出的字符串以'/0'结尾,且由函数自动计算出其长度addr@stRect,/DT_SINGLELINEorDT_CENTERorDT_VCENTERinvokeEndPaint,hWnd,addr@stPs;********************************************************************.elseifeax==WM_COMMANDinvokeMessageBox,NULL,offsetszText,offsetszMsgTitle,MB_OK;********************************************************************.elseifeax==WM_CLOSEinvokeDestroyWindow,hWinMaininvokePostQuitMessage,NULL;********************************************************************.elseinvokeDefWindowProc,hWnd,uMsg,wParam,lParamret.endif;********************************************************************xoreax,eax;eax寄存器清零ret_ProcWinMainendp;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;WinMain函数;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>_WinMainproclocal@stWndClass:WNDCLASSEXlocal@stMsg:MSGinvokeGetModuleHandle,NULL;获取应用程序句柄,这在VC里是通过操作系统传递进来的,但是汇编中需要自己去获取movhInstance,eax;获取到的应用程序句柄在eax中invokeRtlZeroMemory,addr@stWndClass,sizeof@stWndClass;清零;********************************************************************;注册窗口类;********************************************************************invokeLoadCursor,0,IDC_ARROW;加载光标mov@stWndClass.hCursor,eaxpushhInstancepop@stWndClass.hInstancemov@stWndClass.cbSize,sizeofWNDCLASSEXmov@stWndClass.style,CS_HREDRAWorCS_VREDRAWmov@stWndClass.lpfnWndProc,offset_ProcWinMain;设置窗口处理函数;invokeGetStockObject,WHITE_BRUSH;mov@stWndClass.hbrBackground,eaxmov@stWndClass.hbrBackground,COLOR_WINDOW+1mov@stWndClass.lpszClassName,offsetszClassNameinvokeRegisterClassEx,addr@stWndClass;注册窗口类;********************************************************************;建立并显示窗口;********************************************************************invokeCreateWindowEx,WS_EX_CLIENTEDGE,offsetszClassName,offsetszCaptionMain,/WS_OVERLAPPEDWINDOW,/100,100,600,400,/NULL,NULL,hInstance,NULL;创建窗口,发出一个WM_CREATE消息movhWinMain,eax;保存窗口句柄invokeShowWindow,hWinMain,SW_SHOWNORMAL;显示窗口invokeUpdateWindow,hWinMain;发出一个WM_PAINT消息;********************************************************************;第一种消息循环,使用GetMessage,同步的;********************************************************************;.whileTRUE;invokeGetMessage,addr@stMsg,NULL,0,0;.break.ifeax==0;stMsg为0,即收到WM_QUIT消息时退出;invokeTranslateMessage,addr@stMsg;invokeDispatchMessage,addr@stMsg;.endw;********************************************************************;另一种消息循环,使用PeekMessage,异步的;********************************************************************.whileTRUEinvokePeekMessage,addr@stMsg,NULL,0,0,PM_REMOVE.ifeax!=0.break.if@stMsg.message==WM_QUITinvokeTranslateMessage,addr@stMsginvokeDispatchMessage,addr@stMsg.else;空闲时间,可以做其他处理工作.endif.endwret_WinMainendp;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;程序入口点;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>start:call_WinMaininvokeExitProcess,NULL;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>endstart <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> 运行结果: