flat assembler
Message board for the users of flat assembler.

Index > Projects and Ideas > Weird code and programming style

Author
Thread Post new topic Reply to topic
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
This thread is for strange but working code.

I wrote this code. Now it's looking strange even for me. Wink
Code:
                format  PE GUI
                include "WIN32A.INC"

                section ".code" code executable readable writeable
                entry   $
                mov     esp, wicked_stack
MessageBox:     jmp     [__imp__MessageBoxA@16]
ExitProcess:    jmp     [__imp__ExitProcess@4]

eax_eq_literal?_branch:
                cmp     eax, [esp]
                pop     eax
                pop     eax
                jnz     @f
                mov     esp, eax
@@:             ret

                rb      65536

                section ".data" data readable writeable
wicked_stack:
                dd      MessageBox
                dd      HWND_DESKTOP, hello_world, hello_caption, MB_OK+MB_ICONEXCLAMATION
                dd      eax_eq_literal?_branch
                dd      HWND_DESKTOP, goodbye_world, hello_caption, MB_YESNO+MB_ICONQUESTION
                dd      IDYES, goodbye_ok
                dd      MessageBox
                dd      ExitProcess
                dd      HWND_DESKTOP, goto_hell_world, hello_caption, MB_OK+MB_ICONINFORMATION
                dd      0
                dd      -1
goodbye_ok:     dd      ExitProcess
                dd      0
                dd      0

hello_caption   db      "Weird Hello", 0
hello_world     db      "Hello, World!", 0
goodbye_world   db      "Goodbye, World?", 0
goto_hell_world db      "Go to hell, cruel World!", 0

                data    import
                library USER32, "USER32.DLL",\
                        KERNEL32, "KERNEL32.DLL"
                import  USER32,\
                        __imp__MessageBoxA@16, "MessageBoxA"
                import  KERNEL32,\
                        __imp__ExitProcess@4, "ExitProcess"
                end     data    

_________________
"Don't belong. Never join. Think for yourself. Peace." – Victor Stone.
Post 06 Nov 2008, 19:07
View user's profile Send private message Reply with quote
bogdanontanu



Joined: 07 Jan 2004
Posts: 403
Location: Sol. Earth. Europe. Romania. Bucuresti
bogdanontanu
Do I detect some FORTH influences here?
Post 06 Nov 2008, 22:09
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
bogdanontanu,

Not only FORTH. Direct threaded code, I know, but for LSI-11 it's well accepted practice to chain procedures' calls using stack.
Post 07 Nov 2008, 02:02
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-2019, Tomasz Grysztar.

Powered by rwasa.