Attached is a 64-bit Poasm dialog box example.
; Source code assembled with Pelles Macro Assembler, Version 8.00.1
.model flat,fastcall
include ColorDlg.inc
.data
Resource db 'MYDIALOG',0
msg db 'Dialog box example',0
title1 db 'About',0
.data?
hBrush qword ?
.code
start PROC PARMAREA=5*QWORD
LOCAL hModule:QWORD
invoke GetModuleHandle,NULL
mov hModule,rax
invoke DialogBoxParam,hModule,ADDR Resource,NULL,ADDR DlgProc,NULL
invoke ExitProcess,rax
start ENDP
DlgProc PROC hWnd:QWORD,uMsg:QWORD,wParam:QWORD,lParam:QWORD PARMAREA=12*QWORD
LOCAL _hWnd:QWORD
mov _hWnd,rcx
.IF edx==WM_CTLCOLORDLG
invoke CreateSolidBrush,Blue
mov [rip+hBrush],rax
ret
.ELSEIF edx==WM_CLOSE
invoke SendMessage,rcx,WM_COMMAND,IDM_EXIT,0
.ELSEIF edx==WM_COMMAND
mov rax,r8
.IF r9==0
.IF ax==IDM_ABOUT
invoke MessageBox,NULL,ADDR msg,ADDR title1,MB_OK
.ELSEIF ax==IDM_EXIT
invoke DeleteObject,[rip+hBrush]
invoke EndDialog,_hWnd,NULL
.ENDIF
.ELSE
mov rdx,r8
shr edx,16
.IF dx==BN_CLICKED
.IF ax==IDC_ABOUT
invoke SendMessage,_hWnd,WM_COMMAND,IDM_ABOUT,0
.ELSEIF ax==IDC_EXIT
invoke SendMessage,_hWnd,WM_COMMAND,IDM_EXIT,0
.ENDIF
.ENDIF
.ENDIF
.ELSE
mov rax,FALSE
ret
.ENDIF
mov rax,TRUE
ret
DlgProc ENDP
END start
invoke MessageBox,NULL,ADDR msg,ADDR title1,MB_OK
in debugger
mov r9,0
mov r8,offset title1
mov rdx,offset msg
mov rcx,0
call MessageBoxA
although must be
xor r9,r9
mov r8d,offset title1
mov edx,offset msg
xor ecx,ecx
call MessageBoxA
there is inperfect solution in invoke macro
and why
QuoteLOCAL _hWnd:QWORD
mov _hWnd,rcx
although must be
Quotemov hWnd,rcx
Hi Mikl,
Replacing :
LOCAL _hWnd:QWORD
mov _hWnd,rcx
with
mov hWnd,rcx
will not work in Poasm. Disassembling the object module, you get this listing :
DlgProc PROC
sub rsp, 104 ; 0053 _ 48: 83. EC, 68
; Filling space: 3H
; Filler type: mov with same source and destination
; db 48H, 89H, 0C9H
ALIGN 2
cmp edx, 310 ; 005A _ 81. FA, 00000136
jnz ?_001 ; 0060 _ 75, 1D
mov rcx, 16711680 ; 0062 _ 48: C7. C1, 00FF0000
call CreateSolidBrush ; 0069 _ E8, 00000000(rel)
mov qword ptr [hBrush], rax ; 006E _ 48: 89. 05, 00000000(rel)
add rsp, 104 ; 0075 _ 48: 83. C4, 68
ret ; 0079 _ C3
The stack organization of Poasm looks a bit problematic, this is why I prefer to create an additional local variable to preserve hWnd
xor r9,r9 is fine.
You can type mov rdx,offset msg instead of mov edx,offset msg This won't hurt the assembled code. Same for xor rcx,rcx replacing xor ex,ecx
QuoteReplacing :LOCAL _hWnd:QWORD
mov _hWnd,rcx
withmov hWnd,rcx
will not work in Poasm.
I checked it out before you ask a question -- but this is wrong (http://www.cyberforum.ru/images/smilies/negative.gif)-- and in MASM is working correctly
Hi Mikl,
It works correctly both in Masm and HJWasm. It's probably a Poasm specific bug. The only way is to create local variables to preserve the parameters of a procedure.
QuoteIt works correctly both in Masm and HJWasm
Well, I'll try the same in HJWasm -- I have little experience in PoAsm programming but I try to write my own invoke macro
Hi, Vortex!
batcls
set pelleasm=\poasm_new
set filename=%1
if exist %filename%.exe del if exist %filename%.exe
%pelleasm%\bin\poasm /I%pelleasm%\include /AAMD64 /Gr %filename%.asm
if exist %filename%.rc (
%pelleasm%\bin\porc /I%pelleasm%\include %filename%.rc
%pelleasm%\bin\polink /SUBSYSTEM:WINDOWS /ALIGN:16 /MERGE:.data=.text ^
/LARGEADDRESSAWARE:NO /LIBPATH:%pelleasm%\lib /BASE:0x400000 ^
/STUB:%pelleasm%\bin\stubby.exe %filename%.obj %filename%.res
del %filename%.res
) else (
%pelleasm%\bin\polink /SUBSYSTEM:WINDOWS /ALIGN:16 /MERGE:.data=.text ^
/LARGEADDRESSAWARE:NO /LIBPATH:%pelleasm%\lib /BASE:0x400000 ^
/STUB:%pelleasm%\bin\stubby.exe %filename%.obj
)
del %filename%.obj
ColorDlginclude win64a.inc
IDM_ABOUT equ 11
IDM_EXIT equ 12
IDC_ABOUT equ 110
IDC_EXIT equ 120
extern __imp_ExitProcess:qword
extern __imp_DialogBoxParamA:qword
extern __imp_CreateSolidBrush:qword
extern __imp_SendMessageA:qword
extern __imp_MessageBoxA:qword
extern __imp_DeleteObject:qword
extern __imp_EndDialog:qword
.code
start: enter 30h,0
xor r8,r8
mov [rbp+20h],r8
db 41h,0B9h
dd DlgProc ;mov r9d,offset DlgProc
db 0BAh
dd Resource ;mov edx,offset Resource
mov ecx,IMAGE_BASE
call __imp_DialogBoxParamA
xor ecx,ecx
call __imp_ExitProcess
DlgProc:
hDlg equ [rbp+10h]
enter 40h,0
mov hDlg,rcx
cmp edx,WM_CLOSE
je wmCLOSE
cmp edx,WM_CTLCOLORDLG
je wmCTLCOLORDLG
cmp edx,WM_COMMAND
jne wmBYE
wmCOMMAND:movzx eax,r8w
or r9,r9 ;lParam == 0?
jnz @f
cmp ax,IDM_ABOUT ;wParam == IDM_ABOUT ?
jnz a1
db 0BAh
dd msg ;mov edx,offset msg
db 41h,0B8h
dd title1 ;mov r8d,offset title1
xor ecx,ecx
xor r9,r9
call __imp_MessageBoxA
jmp wmBYE
a1: mov ecx,[rip+brush]
call __imp_DeleteObject
xor edx,edx
mov rcx,hDlg
call __imp_EndDialog
jmp wmBYE
@@: mov rdx,r8
shr edx,16 ;cmp dx,BN_CLICKED
jnz wmBYE
xor r9,r9
mov edx,WM_COMMAND
cmp al,IDC_ABOUT
jnz @f
mov r8d,IDM_ABOUT
jmp a2
@@: mov r8d,IDM_EXIT
a2: call __imp_SendMessageA
jmp wmBYE
wmCTLCOLORDLG:mov ecx,Blue
call __imp_CreateSolidBrush
mov [rip+brush],eax
jmp a3
wmCLOSE:xor r9,r9
mov r8d,IDM_EXIT
mov edx,WM_COMMAND
call __imp_SendMessageA
wmBYE: xor eax,eax
a3: leave
retn
;------------------------------------------
Resource db 'MYDIALOG',0
msg db 'Dialog box example',0
title1 db 'About',0
brush dd ?
END start
ColorDlg.rc#include "resource.h"
LANGUAGE LANG_ENGLISH,SUBLANG_ENGLISH_US
MYDIALOG DIALOGEX DISCARDABLE 20, 10, 186, 94, 18481280
STYLE DS_3DLOOK|DS_CENTER|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_VISIBLE
MENU 10000
CAPTION "Dialog box"
FONT 12, "System", 700, 0, 1
{
CONTROL "&About", 110, "Button", WS_TABSTOP, 115, 22, 50, 21, 0, 1234049503
CONTROL "&Exit", 120, "Button", WS_TABSTOP, 115, 51, 50, 21, 0, 1234049503
}
10000 MENU
{
POPUP "&File"
{
MENUITEM "&About", 11
MENUITEM "&Exit", 12
}
}
Hi, Vortex!
how to convert macros written for MASM in the macro for the Poasm?
movr macro x,y; mov r9d,offset DlgProc
mov x,0
org $-4
dd y
endm
Hi Mikl,
Thanks for your example. The macro engine of Poasm has some syntax difference. An example : attached is a Poasm invoke simulator ( 32-bit code. ) Don't forget to build the undecorated import libraries with the MakeLib.bat file.
Hi Mikl,
About your macro :
movr macro x,y; mov r9d,offset DlgProc
mov x,0
org $-4
dd y
endm
Poasm does not accept this statement : org $-4
error: Must be a constant integer expression.