flat assembler
Message board for the users of flat assembler.

Index > Main > Redefining the syntax (flat assembler 1.61)

Goto page Previous  1, 2, 3, 4, 5  Next

Do you like the proposed changes (read below)?
Yes
96%
 96%  [ 24 ]
No
4%
 4%  [ 1 ]
Total Votes : 25

Author
Thread Post new topic Reply to topic
dead_body



Joined: 21 Sep 2005
Posts: 187
Location: Ukraine,Kharkov
dead_body
Quote:
If you can make this to allow nesting, like ExitProcess(GetLastError()), ...

i think i do this(see macro in this post). But there can be many errors.

Here is file to add hll to API.
Code:
macro def@pa_@a1
{
        macro push_args [arg]
        \{
                \reverse
                define status2 0
                match =0 param=),status2 arg
                \\{
                        def@pa_@a1
                        push_args param
                        purge push_args
                        define status2 1
                \\}
                match =0 param=(some,status2 arg
                \\{
                        def@pa_@a1
                        push_args some
                        purge push_args
                        call [param]
                        push eax
                        define status2 1
                \\}
                match =0 param=(,status2 arg
                \\{
                        call [param]
                        push eax
                        define status2 1
                \\}
                match =0,status2
                \\{
                        pushd arg
                \\}
        \}
}


macro hllToFunc [func]
{
        macro func      [sParam]
        \{
                \common
                define status 0
                match =0 =(=),status sParam
                \\{
                        call [func]
                        define status 1
                \\}
                match =0 =(args=),status sParam
                \\{
                        def@pa_@a1
                        push_args args
                        purge push_args
                        call [func]
                        define status 1
                \\}
                match =0 =dd some?,status sParam
                \\{
                       func sParam
                       define status 1
                \\}
                match =0 =:,status sParam
                \\{
                        func sParam
                        define status 1
                \\}
                match =0 =: some?,status sParam
                \\{
                        func sParam
                        define status 1
                \\}
                match =0,status
                \\{
                        unknown syntax.
                \\}
        \}
}
    


here is file to add hll to all func in 'include\APIA\*.inc'
Code:
include "fasmMacroLib\hllToAllFunc\hllToFunc.inc"

macro import garbage,[p1,p2]
{
        hllToFunc p1
}

include 'apia/kernel32.inc'
include 'apia/user32.inc'
include 'apia/gdi32.inc'
include 'apia/advapi32.inc'
include 'apia/comctl32.inc'
include 'apia/comdlg32.inc'
include 'apia/shell32.inc'
include 'apia/wsock32.inc'

purge import

    



Please if you can, test it.
Post 24 Jul 2006, 05:30
View user's profile Send private message Reply with quote
dead_body



Joined: 21 Sep 2005
Posts: 187
Location: Ukraine,Kharkov
dead_body
final version of macro. Just copy it to file, and include it. Then use it!
Code:
macro def@pa_@a1
{
        macro push_args [arg]
        \{
                \reverse
                define status2 0
                match =0 param=),status2 arg
                \\{
                        def@pa_@a1
                        push_args param
                        purge push_args
                        define status2 1
                        right_bracket = right_bracket + 1
                \\}
                match =0 param=(some,status2 arg
                \\{
                        def@pa_@a1
                        push_args some
                        purge push_args
                        call [param]
                        push eax
                        define status2 1
                        left_bracket = left_bracket + 1
                \\}
                match =0 param=(,status2 arg
                \\{
                        call [param]
                        push eax
                        define status2 1
                        left_bracket = left_bracket + 1
                \\}
                match =0,status2
                \\{
                        pushd arg
                \\}
        \}
}

macro hllToFunc [func]
{
        macro func      [sParam]
        \{
                \common
                define status 0
                match =0 =(=),status sParam
                \\{
                        call [func]
                        define status 1
                \\}
                match =0 =(args=),status sParam
                \\{
                        right_bracket = 0
                        left_bracket = 0
                        def@pa_@a1
                        push_args args
                        purge push_args
                        call [func]
                        if right_bracket <> left_bracket
                           display "number of -> '(' not equal to -> ')'",13,10
                        end if
                        define status 1
                \\}
                match =0 =dd some?,status sParam
                \\{
                       func sParam
                       define status 1
                \\}
                match =0 =:,status sParam
                \\{
                        func sParam
                        define status 1
                \\}
                match =0 =: some?,status sParam
                \\{
                        func sParam
                        define status 1
                \\}
                match =0,status
                \\{
                        unknown syntax.
                \\}
        \}
}

macro import garbage,[p1,p2]
{
        hllToFunc p1
}

include 'apia/kernel32.inc'
include 'apia/user32.inc'
include 'apia/gdi32.inc'
include 'apia/advapi32.inc'
include 'apia/comctl32.inc'
include 'apia/comdlg32.inc'
include 'apia/shell32.inc'
include 'apia/wsock32.inc'

purge import
    
Post 28 Jul 2006, 10:18
View user's profile Send private message Reply with quote
dead_body



Joined: 21 Sep 2005
Posts: 187
Location: Ukraine,Kharkov
dead_body
now you can invoke like in C (func()), not only functions, but also labels(or procedures).
But before you invoke label, you must add it to macro list.
You can easy done it with hllToProc macro.

Code:
macro call_proc?func? func_or_proc
{
        define hTFs 0
        match =1,func_or_proc#.proc
        \{ call func_or_proc
           define hTFs 1 \}
        match =0,hTFs\{ call [func_or_proc] \}
}

macro def@pa_@a1
{
        macro push_args [arg]
        \{
                \reverse
                define pa_s 0
                match param=),arg
                \\{
                        def@pa_@a1
                        push_args param
                        purge push_args
                        define pa_s 1
                        _@_br1 = _@_br1 + 1
                \\}
                match =0 param=(some,pa_s arg
                \\{
                        def@pa_@a1
                        push_args some
                        purge push_args
                        call_proc?func? param
                        push eax
                        define pa_s 1
                        _@_br1 = _@_br1 - 1
                \\}
                match =0 param=(,pa_s arg
                \\{
                        call_proc?func? param
                        push eax
                        define pa_s 1
                        _@_br1 = _@_br1 - 1
                \\}
                match =0,pa_s\\{ pushd arg \\}
        \}
}

macro hllToFunc [func]
{
        macro func [sParam]
        \{
                \common
                define shTF 0
                match =(=),sParam
                \\{
                        call_proc?func? func
                        define shTF 1
                \\}
                match =0 =(args=),shTF sParam
                \\{
                        _@_br1 = 0
                        def@pa_@a1
                        push_args args
                        purge push_args
                        define hTF_status 0
                        call_proc?func? func
                        if _@_br1 <> 0
                           errror. '(' <> ')'.
                        end if
                        define shTF 1
                \\}
                match =0,shTF\\{ func sParam \\}
        \}
}

macro import garbage,[p1,p2]
{
        hllToFunc p1
}

include '../apia/kernel32.inc'
include '../apia/user32.inc'
include '../apia/gdi32.inc'
include '../apia/advapi32.inc'
include '../apia/comctl32.inc'
include '../apia/comdlg32.inc'
include '../apia/shell32.inc'
include '../apia/wsock32.inc'

purge import

macro hllToProc [proc]
{
        define proc#.proc 1
        hllToFunc proc
}
    



Example:

Code:
include 'C:\important\coding\fasm\INCLUDE\win32ax.inc'
include 'C:\Documents and Settings\dead_body\hllToAllFunc.inc'

hllToProc test_proc,test_2


.code
EntryPoint:

        test_proc(test_2())
        MessageBox(0,"message","hi",test_proc(6))
        ExitProcess(GetLastError())
;there can be many levels of nesting.

proc test_proc a
        xor eax,eax
        mov edx,[a]
        ret
endp

proc test_2
        mov eax,[esp+8]
        ret
endp

.end EntryPoint
    



comments? or bugs?


Last edited by dead_body on 10 Oct 2006, 04:31; edited 1 time in total
Post 09 Oct 2006, 18:50
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
does it supports nesting: ExitProcess(GetLastError())?
Post 09 Oct 2006, 20:12
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
dead_body



Joined: 21 Sep 2005
Posts: 187
Location: Ukraine,Kharkov
dead_body
yes, it supports nesting.
i correct my previous post(rewrite example).
Post 10 Oct 2006, 04:25
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17714
Location: In your JS exploiting you and your system
revolution
dead_body wrote:
Code:
        test_proc(test_2()) 
        MessageBox(0,"message","hi",test_proc(6)) 
        ExitProcess(GetLastError())     
This looks nice for small projects. Can it be made to work with wsprintf?
Post 10 Oct 2006, 10:58
View user's profile Send private message Visit poster's website Reply with quote
dead_body



Joined: 21 Sep 2005
Posts: 187
Location: Ukraine,Kharkov
dead_body
see in macroses.
each function that is listed in include '../apia/*.inc' can be used.
but you must do add esp,4*.. manually.
Post 10 Oct 2006, 18:57
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
does it also support nesting like this: abcd(abcd(abcd()))? Wink
Post 10 Oct 2006, 19:07
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
This is awsome dude!!!
This keeps the source code very readable while having the power of ASM in hands, and can be easily used to port C source code by copying and pasting the functions! Very Happy
This also makes writting C compilers with FASM back-end easier!
This could be improved and added to FASM standard distribution!
Thanks a lot!





This is so cool!!!
Code:
include '%fasminc%\win32ax.inc'
include '%fasminc%\hllToAllFunc.inc'

.code
main:
        MessageBox(0,"Yes or no?","Macro test",MB_YESNO)
        .if eax=IDYES
            MessageBox(0,"Yes!!","",0)
        .else
            MessageBox(0,"No!!","",0)
        .endif
        ExitProcess(0)
.end main 
    

Looks like a HLL, but still has the power of ASM!! Smile
And has the advantage that FASM is very fast. So, even if the source-code is processed a lot, the assembling time is still very fast!
Another advantage is that it's now possible to use good C/C++ editors with code completion (Like Visual Studio or Pelles C) to code with FASM and having the call tips!
I'll test with a more or less big project to see how fast will it be.
I'll post feedback soon!
Post 10 Oct 2006, 22:36
View user's profile Send private message Reply with quote
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
Did some tests.
Works OK with C library:
Code:
include '%fasminc%\win32ax.inc'
include '%fasminc%\hlltoallfunc.inc'

hllToFunc fopen,fprintf, main

EntryPoint:
        LoadLibrary("msvcrt.dll")
        mov [hcrt],eax
        GetProcAddress([hcrt],"fopen")
        mov [fopen],eax
        GetProcAddress([hcrt],"fprintf")
        mov [fprintf],eax

        call main
                ret

;data
hfile dd 0
fopen dd 0
fprintf dd 0
hcrt dd 0       

proc main       
        fopen("test.txt","w")
        mov [hfile],eax
        fprintf([hfile],"Hello world!")
        FreeLibrary([hcrt])
        ExitProcess(0)
endp
.end EntryPoint
    

C or ASM? Looks like the best of both! Very Happy
This was coded using Pelles C IDE (that highlights correctly both C and ASM code and shows call tips), and assembled with FASM from command line.

PS: I don't know if someone will use it for real projects. But I'm having fun and enjoying the power of FASM macros! Laughing


Last edited by OzzY on 10 Oct 2006, 23:30; edited 2 times in total
Post 10 Oct 2006, 23:17
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
sick...

first time i am happy FASM doesn't have inline macros Smile
Post 10 Oct 2006, 23:27
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
MichaelH



Joined: 03 May 2005
Posts: 402
MichaelH
dead_body this is very cool. Now for a really stupid idea. Do you think it's possible to have a macro that can read javascript?

Could be intersting in combination with the dual nature programs.

http://board.flatassembler.net/topic.php?t=5625
Post 10 Oct 2006, 23:28
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17714
Location: In your JS exploiting you and your system
revolution
Ozzy wrote:
Works OK with C library
Don't forget to adjust your stack after the ccall functions in msvcrt.dll. The macros support stdcall, you manually need to "add esp,adjustment" for ccall.
Post 11 Oct 2006, 10:30
View user's profile Send private message Visit poster's website Reply with quote
dead_body



Joined: 21 Sep 2005
Posts: 187
Location: Ukraine,Kharkov
dead_body
does it also support nesting like this: abcd(abcd(abcd()))?

of course.

Do you think it's possible to have a macro that can read javascript?

i can't write such macro. Maybe someone else.
Post 12 Oct 2006, 17:03
View user's profile Send private message Reply with quote
TmX



Joined: 02 Mar 2006
Posts: 824
Location: Jakarta, Indonesia
TmX
Code:
include '%fasminc%\win32ax.inc'
include '%fasminc%\hllToAllFunc.inc'

.code
main:
        MessageBox(0,"Yes or no?","Macro test",MB_YESNO)
        .if eax=IDYES
            MessageBox(0,"Yes!!","",0)
        .else
            MessageBox(0,"No!!","",0)
        .endif
        ExitProcess(0)
.end main  [quote][/quote]    


This code won't compile (always says "Error : Out of memory")
until I change the memory needed to 32768. Maybe you could explain this ?
Post 13 Oct 2006, 05:31
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
i will try to explain: this macro is just demonstration of what we CAN do, not what we SHOULD be using. It eats up lot of memory for every procedure that can be called with () style. Every such procedure is declared as macro, that checks if it has "(" and ")" as arguments... etc

if you like this style of coding you can use C, and you will also gain cross-processor portability, and otherwise use pure assembly or neat stdcall / invoke macros
Post 13 Oct 2006, 08:58
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7801
Location: Kraków, Poland
Tomasz Grysztar
It can be made to eat less memory by moving all the stuff into a single external macro and defining each procedure macro as a simple wrapper.
Post 13 Oct 2006, 09:37
View user's profile Send private message Visit poster's website Reply with quote
dead_body



Joined: 21 Sep 2005
Posts: 187
Location: Ukraine,Kharkov
dead_body
It eats up lot of memory for every procedure that can be called with () style. Every such procedure is declared as macro, that checks if it has "(" and ")" as arguments... etc

here is a new version of macro:
Code:
macro call_proc?func? func_or_proc { define hTFs 0
        match =1,func_or_proc#.proc \{ call func_or_proc
           define hTFs 1 \}
        match =0,hTFs \{ call [func_or_proc] \} }

macro def@pa_@a1 { macro push_args [arg] \{ \reverse
                define pa_s 0
                match param=),arg \\{ def@pa_@a1
                        push_args param
                        define pa_s 1
                        _@_br1 = _@_br1 + 1 \\}
                match =0 param=(some,pa_s arg \\{ def@pa_@a1
                        push_args some
                        call_proc?func? param
                        push eax
                        define pa_s 1
                        _@_br1 = _@_br1 - 1 \\}
                match =0 param=(,pa_s arg \\{ call_proc?func? param
                        push eax
                        define pa_s 1
                        _@_br1 = _@_br1 - 1 \\}
                match =0,pa_s \\{ pushd arg \\}
                purge push_args \} }

macro opt1 func { call_proc?func? func
        define shTF 1 }

macro opt2 func,[args] { common
        _@_br1 = 0
        def@pa_@a1
        push_args args
        call_proc?func? func
        if _@_br1 <> 0
           errror. '(' <> ')'.
        end if
        define shTF 1 }

macro hllToFunc [func] {
        macro func [sParam] \{ \common
                define shTF 0
                match =(=),sParam \\{ opt1 func\\}
                match =(args=),sParam \\{ opt2 func,args \\}
                match =0,shTF \\{ func sParam \\} \} }

macro hllToProc [proc] { define proc#.proc 1
        hllToFunc proc }

macro import garbage,[p1,p2] { hllToFunc p1 }

include '../apia/kernel32.inc'
include '../apia/user32.inc'
include '../apia/gdi32.inc'
include '../apia/advapi32.inc'
include '../apia/comctl32.inc'
include '../apia/comdlg32.inc'
include '../apia/shell32.inc'
include '../apia/wsock32.inc'

purge import

macro opt3
{
        macro import garbage,[p1,p2] \{ purge p1 \}
        include '../apia/kernel32.inc'
        include '../apia/user32.inc'
        include '../apia/gdi32.inc'
        include '../apia/advapi32.inc'
        include '../apia/comctl32.inc'
        include '../apia/comdlg32.inc'
        include '../apia/shell32.inc'
        include '../apia/wsock32.inc'
        purge import
        purge hllToProc
        purge hllToFunc
        purge opt1
        purge opt2
        purge def@pa_@a1
        purge call_proc?func?
}

macro .end param
{
        opt3
        purge opt3
        .end param
}    


i don't have time to check if it works now, but i think it works. Question

in this version i optimized the size of memory you need to compile.
now you can compile examples with 16000 kilobytes.

test example:
Code:
include 'win32ax.inc'
include 'HLA\hllToAllFunc.inc'

.code 
EntryPoint:
        rept 45 {
        MessageBox(0,"Yes or no?","Macro test",MB_YESNO)
        .if eax = IDYES
            MessageBox(0,"Yes!!","",0)
        .else 
            MessageBox(0,"No!!","",0)
        .endif 
        ExitProcess(0)
        }

.end EntryPoint
    


comments? feature request? in next version i will optimized macroses more to size, if I can.
Post 13 Oct 2006, 14:24
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
dead_body: i hope you don't take that macro too seriously. remember that it is very limiting...

PS: you should define macro to push single argument, and make it overloadable, so it will be possible to add custom types of arguments
Post 13 Oct 2006, 15:00
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
dead_body



Joined: 21 Sep 2005
Posts: 187
Location: Ukraine,Kharkov
dead_body
you should define macro to push single argument, and make it overloadable, so it will be possible to add custom types of arguments

i can't understand what you think about? give an example please,if you have free time.

remember that it is very limiting...
Question
Post 13 Oct 2006, 16:56
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, 4, 5  Next

< 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.