📄 wap.asm
字号:
; Copyright (c) 1993 by Borland International, Inc.
;
; * Borland Turbo Assembler 4.0 *
;
; * Windows Application Example in Assembly *
;
; This example (WAP.ASM) will put up a window and beep when the
; right mouse button is pressed. When the left mouse button is
; pressed, it will put up a message box.
;
;This file is originally by and belongs to Borland International.
;It was modified for ASM++ to demonstrate how to assemble a WIN16 file
;Read WAP.TXT for more. Find a WIN16 compatible linker and link it with
;WAP.DEF
.model large, PASCAL
ifdef ??asmpp
.format omf16
endif
include windows.inc
extrn BEGINPAINT:FAR
extrn CREATEWINDOW:FAR
extrn DEFWINDOWPROC:FAR
extrn DISPATCHMESSAGE:FAR
extrn ENDPAINT:FAR
extrn GETMESSAGE:FAR
extrn GETSTOCKOBJECT:FAR
extrn INITAPP:FAR
extrn INITTASK:FAR
extrn INVALIDATERECT:FAR
extrn LOADCURSOR:FAR
extrn MESSAGEBEEP:FAR
extrn MESSAGEBOX:FAR
extrn POSTQUITMESSAGE:FAR
extrn REGISTERCLASS:FAR
extrn SHOWWINDOW:FAR
extrn TEXTOUT:FAR
extrn TRANSLATEMESSAGE:FAR
extrn UPDATEWINDOW:FAR
extrn WAITEVENT:FAR
DGROUP Group DATA
CODE segment 'CODE' Use16
ifndef ??asmpp
assume cs:code,ds:data
endif
;-----------------------------------------------------------------------------
start:
.286
mov ax, data
mov ds, ax ; set up data segment
;Windows initialization. Sets up registers and stack.
;INITTASK returns:
; Failure:
; AX = zero if it failed
; Success:
; AX = 1
; CX = stack limit
; DX = cmdShow parameter to CreateWindow
; ES:BX = -> DOS format command line (ES = PSP address)
; SI = hPrevinstance
; DI = hinstance
call INITTASK
or ax,ax
jnz @@OK
jmp @@Fail
@@OK: mov [psp],es
mov word ptr [pszCmdline],bx
mov [hPrev],si
mov [hInstance],di
mov [cmdShow],dx
;Initialize the Windows App
xor ax,ax
push ax
call WAITEVENT
push [hInstance]
call INITAPP
or ax,ax
jnz @@InitOK
@@Fail:
mov ax, 4CFFh
int 21h ; terminate program
@@InitOK:
;-----------------------------------------------------------------------------
; This is generally where WinMain is called. We won't use a WinMain, since
; this app is 100% assembly.
call messagebox,0,ds,offset ASMPP_Msg,ds,offset ASMPP_Title,0
cmp [hPrev], 0
jne already_running
; initialize the WndClass structure
mov [wc.clsStyle], CS_HREDRAW + CS_VREDRAW
mov word ptr [wc.clsLpfnWndProc], offset WndProc
mov word ptr [wc.clsLpfnWndProc+2],cs
mov [wc.clsCbClsExtra], 0
mov [wc.clsCbWndExtra], 0
mov ax, [hInstance]
mov [wc.clsHInstance], ax
mov [wc.clsHIcon], 0
push 0
push IDC_ARROW
call LOADCURSOR
mov [wc.clsHCursor], ax
push WHITE_BRUSH
call GETSTOCKOBJECT
mov [wc.clsHbrBackground], ax
mov word ptr [wc.clsLpszMenuName], 0
mov word ptr [wc.clsLpszMenuName+2], 0
mov word ptr [wc.clsLpszClassName], offset szClassName
mov word ptr [wc.clsLpszClassName+2], ds
push ds
push offset wc
call REGISTERCLASS
already_running:
push ds
push offset szClassName ; Class name
push ds
push offset szTitleName ; Title string
push WS_OVERLAPPEDWINDOW+WS_VISIBLE ; high word of Style
push 0 ; low word of Style
push CW_USEDEFAULT ; x
push CW_USEDEFAULT ; y
push CW_USEDEFAULT ; width
push CW_USEDEFAULT ; height
push 0 ; parent hwnd
push 0 ; menu
push [hInstance] ; hInstance
push 0 ; lpParam
push 0 ; lpParam
call CREATEWINDOW
mov [newhwnd], ax
push [newhwnd]
push [cmdShow]
call SHOWWINDOW
push [newhwnd]
call UPDATEWINDOW
msg_loop:
push ds
push offset msg
push 0
push 0
push 0
call GETMESSAGE
cmp ax, 0
je end_loop
push ds
push offset msg
call TRANSLATEMESSAGE
push ds
push offset msg
call DISPATCHMESSAGE
jmp msg_loop
end_loop:
mov ax, [msg.msWPARAM]
mov ah, 4Ch
int 21h
;-----------------------------------------------------------------------------
WndProc proc FAR PASCAL, hwnd:WORD, wmsg:WORD, wparam:WORD, lparam:DWORD
mov ax,hwnd
mov ax,wmsg
mov ax,wparam
mov ax,word ptr lparam
cmp wmsg, WM_DESTROY
je wmdestroy
cmp wmsg, WM_LBUTTONDOWN
je wmlbuttondown
cmp wmsg, WM_CREATE
je wmcreate
cmp wmsg, WM_RBUTTONDOWN
je wmrbuttondown
cmp wmsg, WM_PAINT
je wmpaint
jmp defWndProc
wmrbuttondown:
jmp wmrbuttondown2
wmpaint:
push [hwnd]
push ds
push offset lppaint
call BEGINPAINT
push ax ; the DC
mov bx, [mbx_count]
add bl, '0'
mov [s_num], bl
push 5 ; x
push 5 ; y
push ds
push offset szPaint ; string
push MSG_L ; length of string
call TEXTOUT
push [hwnd]
push ds
push offset lppaint
call ENDPAINT
mov ax, 0
jmp finish
wmcreate:
mov ax, 0
jmp finish
defWndProc:
push hwnd
push wmsg
push wparam
push dword ptr lparam
call DEFWINDOWPROC
jmp finish
wmdestroy:
push 0
call POSTQUITMESSAGE
mov ax, 0
jmp finish
wmlbuttondown:
cmp [mbx_count], 5
jae finish
inc [mbx_count]
push [hwnd]
push 0
push 0
push 0
call INVALIDATERECT ; repaint window
push 0
push ds
push offset szMsg
push ds
push offset szCapt
push 0
call MESSAGEBOX ; put up msgbox and wait
mov ax, 0
dec [mbx_count]
push [hwnd]
push 0
push 0
push 0
call INVALIDATERECT ; repaint window again
jmp finish
wmrbuttondown2:
push 0
call MESSAGEBEEP
jmp finish
finish:
mov dx, 0
ret
mov ax,0
WndProc endp
;-----------------------------------------------------------------------------
public WndProc
ifdef ??asmpp
end start
endif
ends
DATA segment 'DATA'
db 16 dup (0) ; Filler for Windows Task manager.
; This *MUST* be declared, otherwise
; Windows will clobber part of your data
; segment. For additional information on
; Windows Task managment and what
; happens when Windows apps start up, see
; "Windows Internals" - Matt Pietrek,
; 1993 Addison Wesley
psp dw ?
pszCmdline dw ?
hPrev dw ?
hInstance dw ?
cmdShow dw ?
newhwnd dw 0
lppaint PAINTSTRUCT
msg MSGSTRUCT
wc WNDCLASS
mbx_count dw 0
ASMPP_Msg db 'ASM++ daddy',0
ASMPP_Title db 'ASM++ baba',0
szTitleName db 'Windows Assembly Program',0
szClassName db 'ASMCLASS',0
szMsg db 'Hello there folks',0
szCapt db 'Left Mouse',0
szPaint db 'There are '
s_num db '0 MessageBoxes waiting.',0
MSG_L EQU ($-szPaint)-1
data ends
ifndef ??asmpp
end start
endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -