News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

POASM 1k example.

Started by hutch--, January 26, 2006, 12:09:41 AM

Previous topic - Next topic

hutch--

There has been some concern raised that all of the extra capacity that Pelle has written into POASM may effect it as a low level assembler. here is a 1k example of a working window that shows how to do it at true low level while building the minimum PE file size.

The example show just a little of the power of POASM and POLINK used in conjunction to produce the minimum size valid PE file while having the full range of assembler coded speed.


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    .486                      ; create 32 bit code
    .model flat, stdcall      ; 32 bit memory model
    option casemap :none      ; case sensitive

    include poasm1k.inc       ; local includes for this file

  .code
    szClassName db "POASM 1k", 0

  start:

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    push ebp
    mov ebp, esp

    sub esp, 96

    xor edi, edi
    mov esi, 400000h

    mov ebx, OFFSET szClassName

    push IDC_ARROW
    push edi
    call LoadCursor

    mov DWORD PTR [ebp-96], 48
    mov DWORD PTR [ebp-92], CS_VREDRAW or CS_HREDRAW
    mov DWORD PTR [ebp-88], OFFSET MyWndProc
    mov DWORD PTR [ebp-84], edi
    mov DWORD PTR [ebp-80], edi
    mov DWORD PTR [ebp-76], esi
    mov DWORD PTR [ebp-72], edi
    mov DWORD PTR [ebp-68], eax
    mov DWORD PTR [ebp-64], COLOR_BTNFACE+1
    mov DWORD PTR [ebp-60], edi
    mov DWORD PTR [ebp-56], ebx
    mov DWORD PTR [ebp-52], edi

    lea eax, [ebp-96]
    push eax
    call RegisterClassEx

    mov ecx, CW_USEDEFAULT

    push edi
    push esi
    push edi
    push edi
    push edi
    push ecx
    push edi
    push ecx
    push WS_OVERLAPPEDWINDOW
    push ebx
    push ebx
    push edi
    call CreateWindowEx

    push SW_SHOWNORMAL
    push eax
    call ShowWindow

    lea ebx, [ebp-48]

  StartLoop:
    push ebx
    call DispatchMessage

    push edi
    push edi
    push edi
    push ebx
    call GetMessage

    test al, al
    jnz StartLoop

    leave
    retn

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

MyWndProc:

    push ebp
    mov ebp, esp

    cmp DWORD PTR [ebp+12], WM_DESTROY
    jne @F
      push NULL
      call PostQuitMessage
    @@:

    push DWORD PTR [ebp+20]
    push DWORD PTR [ebp+16]
    push DWORD PTR [ebp+12]
    push DWORD PTR [ebp+8]
    call DefWindowProc

    leave
    ret 16

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start

[attachment deleted by admin]
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

MusicalMike

Could you clarify what you mean by this? I don't understand what a windows app written in pure asm is supposed to proove about POASM. By the way, I have my own version of this code, that appeared in another post.


.386
.model flat, stdcall

option casemap:none

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

includelib gdi32.lib
includelib user32.lib
includelib kernel32.lib

.code
wc        dd        12        dup(00h)
ps        dd        16        dup(00h)
msg       dd         7        dup(00h)
hwnd      dd        00h
dc        dd        00h
szName    db        "MainWindow"
szApp     db        "My App"

Start:          mov [wc + 00], 30h
mov [wc + 04], 03h
mov [wc + 08], WndProc
mov [wc + 12], 00h
mov [wc + 16], 00h
mov [wc + 20], 400000h
mov [wc + 32], 10h
mov [wc + 36], 00h
mov [wc + 40], offset szName
push 7F00h
push 00h
call LoadIcon
mov [wc + 24], eax
mov [wc + 44], 00h
push 7F00h
push 00h
call LoadCursor
mov [wc + 28], eax
push offset wc
call RegisterClassEx
push 00h
push 400000h
push 00h
push 00h
push 300
push 300
push 300
push 300
push 0CF0000h
push offset szApp
push offset szName
push 00h
call CreateWindowEx
mov hwnd, eax
push 01h
push hwnd
call ShowWindow
push hwnd
call UpdateWindow
@@:             push 00h
push 00h
push 00h
push offset msg
call GetMessage
cmp eax, 00h
je @F
push offset msg
call TranslateMessage
push offset msg
call DispatchMessage
jmp @B
@@:             push [msg + 12]
call ExitProcess
WndProc:        push ebp
mov ebp, esp
@@:             cmp dword ptr ss:[ebp + 0Ch], 002h
jne @F
push 00h
call PostQuitMessage
jmp break
@@:             cmp dword ptr ss:[ebp + 0Ch], 111h
jne @F
push dword ptr ss:[ebp + 08h]
call DestroyWindow
jmp break
@@:             cmp dword ptr ss:[ebp + 0Ch], 00Fh
jne @F
push offset ps
push dword ptr ss:[ebp + 08h]
call BeginPaint
mov dc, eax
call EndPaint
jmp break
@@:             push dword ptr ss:[ebp + 14h]
push dword ptr ss:[ebp + 10h]
push dword ptr ss:[ebp + 0Ch]
push dword ptr ss:[ebp + 08h]
call DefWindowProc
leave
ret
break:          xor eax, eax
leave
ret

End Start


hutch--

#2
Mike,

You would have to try and understand the English language in the first sentence of the post you have answered.

A quick look at your code says you would have to build it with the ".text" section writable otherwise it would GP fault at runtime with a write access error to the .CODE section. Perhaps you could also post the build technique with your code so we at least know what it was built with.

As an additional note, your code should balance the stack in the WndProc using the C2 opcode. You can do this with "RET 16".
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

MusicalMike

I like to use WinAsm Studio. The command line parameters passed to ml.exe were the default ones passed by WinAsm Studio. I am in school right now, and have no way of checking what they are. I guess the reason I didn't understand the plain english is because I would take it for granted that a macro assembler should support low level assembly also. Another thing I noticed after looking at it a second time was that you used the stack to store your WNDCLASS structure rather than allocating global memory for it. I didn't do that in my code, so the exe file generated by my code would be much bigger than yours. I can't believe I missed this the first time.