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)? | ||||||||||||||
|
||||||||||||||
Total Votes : 25 |
Author |
|
dead_body 28 Jul 2006, 10:18
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 |
|||
28 Jul 2006, 10:18 |
|
dead_body 09 Oct 2006, 18:50
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 |
|||
09 Oct 2006, 18:50 |
|
vid 09 Oct 2006, 20:12
does it supports nesting: ExitProcess(GetLastError())?
|
|||
09 Oct 2006, 20:12 |
|
dead_body 10 Oct 2006, 04:25
yes, it supports nesting.
i correct my previous post(rewrite example). |
|||
10 Oct 2006, 04:25 |
|
revolution 10 Oct 2006, 10:58
dead_body wrote:
|
|||
10 Oct 2006, 10:58 |
|
dead_body 10 Oct 2006, 18:57
see in macroses.
each function that is listed in include '../apia/*.inc' can be used. but you must do add esp,4*.. manually. |
|||
10 Oct 2006, 18:57 |
|
vid 10 Oct 2006, 19:07
does it also support nesting like this: abcd(abcd(abcd()))?
|
|||
10 Oct 2006, 19:07 |
|
OzzY 10 Oct 2006, 22:36
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! 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!! 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! |
|||
10 Oct 2006, 22:36 |
|
OzzY 10 Oct 2006, 23:17
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! 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! Last edited by OzzY on 10 Oct 2006, 23:30; edited 2 times in total |
|||
10 Oct 2006, 23:17 |
|
vid 10 Oct 2006, 23:27
sick...
first time i am happy FASM doesn't have inline macros |
|||
10 Oct 2006, 23:27 |
|
MichaelH 10 Oct 2006, 23:28
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 |
|||
10 Oct 2006, 23:28 |
|
revolution 11 Oct 2006, 10:30
Ozzy wrote: Works OK with C library |
|||
11 Oct 2006, 10:30 |
|
dead_body 12 Oct 2006, 17:03
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. |
|||
12 Oct 2006, 17:03 |
|
TmX 13 Oct 2006, 05:31
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 ? |
|||
13 Oct 2006, 05:31 |
|
vid 13 Oct 2006, 08:58
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 |
|||
13 Oct 2006, 08:58 |
|
Tomasz Grysztar 13 Oct 2006, 09:37
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.
|
|||
13 Oct 2006, 09:37 |
|
dead_body 13 Oct 2006, 14:24
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. 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. |
|||
13 Oct 2006, 14:24 |
|
vid 13 Oct 2006, 15:00
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 |
|||
13 Oct 2006, 15:00 |
|
dead_body 13 Oct 2006, 16:56
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... |
|||
13 Oct 2006, 16:56 |
|
Goto page Previous 1, 2, 3, 4, 5 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.