flat assembler
Message board for the users of flat assembler.

Index > Windows > MASM -> fasm (How to convert)

Author
Thread Post new topic Reply to topic
Postal



Joined: 28 May 2006
Posts: 12
Location: Russia
Postal 28 May 2006, 21:35
;Please help to convert this example.

Code:
.386
.model flat,stdcall
option casemap:none

include windows.inc
include user32.inc
include kernel32.inc

includelib user32.lib
includelib kernel32.lib

WinMain proto :DWORD,:DWORD,:DWORD,:DWORD

.data
ClassName       db "SimpleWinClass",0
AppName         db "Our First Window",0

.data?
hInstance       dd ?
CommandLine     dd ?

.code
start:
        invoke  GetModuleHandle,        NULL
        mov     hInstance,                      eax
        invoke  GetCommandLine
        mov     CommandLine,            eax
        invoke  WinMain,                hInstance,\
                                                NULL,\
                                                CommandLine,\
                                                SW_SHOWDEFAULT
        invoke  ExitProcess,    eax

WinMain proc    hInst:HINSTANCE,\
                hPrevInst:HINSTANCE,\
                CmdLine:LPSTR,\
                CmdShow:DWORD

        LOCAL wc:WNDCLASSEX
        LOCAL msg:MSG
        LOCAL hwnd:HWND
        
        mov             wc.cbSize,              SIZEOF WNDCLASSEX
        mov             wc.style,               CS_HREDRAW or CS_VREDRAW
        mov             wc.lpfnWndProc,         OFFSET WndProc
        mov             wc.cbClsExtra,          NULL
        mov             wc.cbWndExtra,          NULL
        push hInstance
        pop             wc.hInstance
        mov             wc.hbrBackground,       COLOR_WINDOW+1
        mov             wc.lpszMenuName,        NULL
        mov             wc.lpszClassName,       OFFSET ClassName
        invoke  LoadIcon,                       NULL,\
                                                        IDI_APPLICATION
        mov             wc.hIcon,                       eax
        mov             wc.hIconSm,             eax
        invoke  LoadCursor,             NULL,\
                                                        IDC_ARROW
        mov             wc.hCursor,             eax
        invoke  RegisterClassEx,        addr wc
        invoke  CreateWindowEx, NULL,\
                                                        addr ClassName,\
                                                        addr AppName,\
                                                        WS_OVERLAPPEDWINDOW,\
                                                        CW_USEDEFAULT,\
                                                        CW_USEDEFAULT,\
                                                        CW_USEDEFAULT,\
                                                        CW_USEDEFAULT,\
                                                        NULL,\
                                                        NULL,\
                                                        hInst,\
                                                        NULL
        mov             hwnd,                   eax
        invoke  ShowWindow,             hwnd,\
                                                        SW_SHOWNORMAL
        invoke UpdateWindow,            hwnd
        .WHILE TRUE
                invoke  GetMessage,     addr msg,\
                                                        NULL,\
                                                        0,\
                                                        0
                .BREAK .IF (!eax)
                invoke  TranslateMessage,       addr msg
                invoke  DispatchMessage,        addr msg
        .ENDW
        mov             eax,                            msg.wParam
        ret
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
        .if uMsg==WM_DESTROY
                invoke  PostQuitMessage,        NULL
        .else
                invoke DefWindowProc,           hWnd,\
                                                                uMsg,\
                                                                wParam,\
                                                                lParam          
                ret
        .endif
        xor             eax,                            eax
        ret
WndProc endp
end start
    
Post 28 May 2006, 21:35
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 28 May 2006, 22:16
Check this one
Code:
include 'WIN32AXP.INC'

HINSTANCE equ DWORD
LPSTR     equ DWORD
HWND      equ DWORD
WPARAM    equ DWORD
LPARAM    equ DWORD
UINT      equ DWORD

.data
ClassName       db "SimpleWinClass",0 
AppName         db "Our First Window",0 

hInstance       dd ?
CommandLine     dd ? 

.code 
start: 
        invoke  GetModuleHandle,        NULL 
        mov     [hInstance],                      eax
        invoke  GetCommandLine 
        mov     [CommandLine],            eax
        stdcall  WinMain,                hInstance,\
                                                NULL,\ 
                                                CommandLine,\ 
                                                SW_SHOWDEFAULT 
        invoke  ExitProcess,    eax 

proc WinMain,   hInst:HINSTANCE,\
                hPrevInst:HINSTANCE,\ 
                CmdLine:LPSTR,\ 
                CmdShow:DWORD
        local wc:WNDCLASSEX
        local msg:MSG
        local hwnd:DWORD
         
        mov             [wc.cbSize],              sizeof.WNDCLASSEX
        mov             [wc.style],               CS_HREDRAW or CS_VREDRAW
        mov             [wc.lpfnWndProc],         WndProc
        mov             [wc.cbClsExtra],          NULL
        mov             [wc.cbWndExtra],          NULL
        push [hInstance]
        pop             [wc.hInstance]
        mov             [wc.hbrBackground],       COLOR_WINDOW+1
        mov             [wc.lpszMenuName],        NULL
        mov             [wc.lpszClassName],       ClassName
        invoke  LoadIcon,                       NULL,\ 
                                                        IDI_APPLICATION 
        mov             [wc.hIcon],                       eax
        mov             [wc.hIconSm],             eax
        invoke  LoadCursor,             NULL,\ 
                                                        IDC_ARROW 
        mov             [wc.hCursor],             eax
        invoke  RegisterClassEx,        addr wc 
        invoke  CreateWindowEx, NULL,\ 
                                                        ClassName,\
                                                        AppName,\
                                                        WS_OVERLAPPEDWINDOW,\ 
                                                        CW_USEDEFAULT,\ 
                                                        CW_USEDEFAULT,\ 
                                                        CW_USEDEFAULT,\ 
                                                        CW_USEDEFAULT,\ 
                                                        NULL,\ 
                                                        NULL,\ 
                                                        [hInst],\
                                                        NULL 
        mov             [hwnd],                   eax
        invoke  ShowWindow,             [hwnd],\
                                                        SW_SHOWNORMAL 
        invoke UpdateWindow,            [hwnd]
        .while TRUE
                invoke  GetMessage,     addr msg,\
                                                        0,\
                                                        0,\ 
                                                        0 
                test eax, eax
                jz .endWhile
                invoke  TranslateMessage, addr      msg
                invoke  DispatchMessage,  addr      msg
        .endw
        .endWhile:
        mov             eax,                            [msg.wParam]
        ret 
endp

proc WndProc, hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
        .if [uMsg]=WM_DESTROY
                invoke  PostQuitMessage,        NULL 
        .else 
                invoke DefWindowProc,           [hWnd],\
                                                                [uMsg],\
                                                                [wParam],\
                                                                [lParam]
                ret 
        .endif 
        xor             eax,                            eax 
        ret 
endp
.end start    
Post 28 May 2006, 22:16
View user's profile Send private message Reply with quote
Postal



Joined: 28 May 2006
Posts: 12
Location: Russia
Postal 29 May 2006, 08:45
Thank you! Razz
Post 29 May 2006, 08:45
View user's profile Send private message Reply with quote
Postal



Joined: 28 May 2006
Posts: 12
Location: Russia
Postal 29 May 2006, 13:42
I'm added ".break" and ".breakif" directives.
Please check it.

;Before
test eax, eax
jz .endWhile

;Now:
.breakif (~eax)

Code:
;if.inc******************************
macro JCOND label,v1,c,v2
{
 match any,c
 \{
   cmp v1,v2
   j\#c label
 \}
 match ,c
 \{
   PARSECOND parsed@cond,v1
   match cond,parsed@cond \\{ JCONDEXPR label,cond \\}
 \}
}

macro .break
{
        jmp     __ENDW
}

macro .breakif [arg]
{
        JCOND __ENDW,arg
}
    


Code:
include '%fasminc%\win32ax.inc'
include 'if.inc'

HINSTANCE       equ DWORD
LPSTR           equ DWORD
HWND            equ DWORD
WPARAM          equ DWORD
LPARAM          equ DWORD
UINT            equ DWORD

.data
ClassName       db "SimpleWinClass",0
AppName         db "Our First Window",0

hInstance       dd ?
CommandLine     dd ?

.code
start:
        invoke  GetModuleHandle,        NULL
        mov             [hInstance],            eax
        invoke  GetCommandLine
        mov             [CommandLine],          eax
        stdcall WinMain,                        [hInstance],\
                                                                NULL,\
                                                                [CommandLine],\
                                                                SW_SHOWDEFAULT
        invoke  ExitProcess,            eax

proc WinMain,   hInst:HINSTANCE,\
                                hPrevInst:HINSTANCE,\
                                CmdLine:LPSTR,\
                                CmdShow:DWORD

        local wc:WNDCLASSEX
        local msg:MSG
        local hwnd:DWORD

        mov             [wc.cbSize],            sizeof.WNDCLASSEX
        mov             [wc.style],                     CS_HREDRAW or CS_VREDRAW
        mov             [wc.lpfnWndProc],       WndProc
        mov             [wc.cbClsExtra],        NULL
        mov             [wc.cbWndExtra],        NULL
        push    [hInstance]
        pop             [wc.hInstance]
        mov             [wc.hbrBackground],     COLOR_WINDOW+1
        mov             [wc.lpszMenuName],      NULL
        mov             [wc.lpszClassName],     ClassName
        invoke  LoadIcon,                       NULL,\
                                                                IDI_APPLICATION
        mov             [wc.hIcon],                     eax
        mov             [wc.hIconSm],           eax
        invoke  LoadCursor,                     NULL,\
                                                                IDC_ARROW
        mov             [wc.hCursor],           eax
        invoke  RegisterClassEx,        addr wc
        invoke  CreateWindowEx,         NULL,\
                                                                ClassName,\
                                                                AppName,\
                                                                WS_OVERLAPPEDWINDOW,\
                                                                CW_USEDEFAULT,\
                                                                CW_USEDEFAULT,\
                                                                CW_USEDEFAULT,\
                                                                CW_USEDEFAULT,\
                                                                NULL,\
                                                                NULL,\
                                                                [hInst],\
                                                                NULL
        mov             [hwnd],                         eax
        invoke  ShowWindow,                     [hwnd],\
                                                                SW_SHOWNORMAL
        invoke  UpdateWindow,           [hwnd]
        .while (TRUE)
                invoke  GetMessage,                     addr msg,\
                                                                        0,\
                                                                        0,\
                                                                        0
;               test eax, eax
;               jz .endWhile
                .breakif (~eax)
                invoke  TranslateMessage,       addr msg
                invoke  DispatchMessage,        addr msg
        .endw
;       .endWhile:
        mov             eax,                            [msg.wParam]
        ret
endp

proc WndProc,   hWnd:HWND,\
                                uMsg:UINT,\
                                wParam:WPARAM,\
                                lParam:LPARAM

        .if ([uMsg]=WM_DESTROY)
                invoke  PostQuitMessage,        NULL
        .else
                invoke  DefWindowProc,          [hWnd],\
                                                                        [uMsg],\
                                                                        [wParam],\
                                                                        [lParam]
                ret
        .endif
        xor             eax,                            eax
        ret
endp
.end start
    
Post 29 May 2006, 13:42
View user's profile Send private message Reply with quote
Postal



Joined: 28 May 2006
Posts: 12
Location: Russia
Postal 31 May 2006, 19:11
Code:
; Macroinstructions for HLL-style conditional operations

macro .continue
{
        jmp     __WHILE
}

macro .continueif [arg]
{
        JCOND   __WHILE,arg
}

macro .break
{
        jmp     __ENDW
}

macro .breakif [arg]
{
        JCOND   __ENDW,arg
}

macro JCOND label,v1,c,v2
{
        match any,c
        \{
                cmp v1,v2
                j\#c label
        \}
        match ,c
        \{
                PARSECOND parsed@cond,v1
                match cond,parsed@cond \\{ JCONDEXPR label,cond \\}
        \}
}
    


COOL?
Smile Smile Smile
Post 31 May 2006, 19:11
View user's profile Send private message Reply with quote
Postal



Joined: 28 May 2006
Posts: 12
Location: Russia
Postal 01 Jun 2006, 10:44
How to make in fasm section ".data?" ??

In MASM (for example):
.data?
buffer db 100000 dup (?)

Then size of .exe file is SMALL !!!!

In fasm:
.data
buffer db 100000 dup (?)

Then size of .exe file is big... Sad
Post 01 Jun 2006, 10:44
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 01 Jun 2006, 13:58
Post 01 Jun 2006, 13:58
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.