flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Quick Question on Macros |
Author |
|
vid 23 Aug 2004, 19:49
you are right with your result, except one thing, macro has to be defined before it is used. Your example will be preprocessed to
Code: jmp code label var1 db 10 label var2 db 11 code: switch var1, var2 and then during assembly you will get error saying "switch" is not name of instruction or directive. |
|||
23 Aug 2004, 19:49 |
|
Imagist 24 Aug 2004, 03:04
So recursive macros are impossible. Darn. And I should do:
Code: jmp code label var1 db 10 label var2 db 11 macro switch a,b{ mov ax,[a] mov bx,[b] mov [b],ax mov [a],bx } code: switch var1, var2 In my dk_lib (a library for using fasm as an HLL; school project) I have the following macro: macro dk_setupGUI{ format PE GUI 4.0 entry start include '%fasminc%\win32ax.inc' };end macro dk_setupGUI Will this work? Also, do includes work in a similar way to macros, like: Code: ;this is in a file called switch.asm push ax push bx pop ax pop bx Code: ;this is in a file called very-bad-code.asm mov ax, 10 mov bx, 11 include 'switch.asm' ;now ax should be 11 and bx 10 so that very-bad-code.asm assembles to: Code: mov ax, 10 mov bx, 11 push ax push bx pop ax pop bx I have many questions, and I am glad there are many here to help, becuase the library is due on next Monday! _________________ Many things are possible. Few things are likely. |
|||
24 Aug 2004, 03:04 |
|
pelaillo 24 Aug 2004, 03:38
Imagist wrote: Also, do includes work in a similar way to macros... Yes, but macros are more flexible. They have arguments, so you could do many things you cannot with includes. Think on macros as text search and replace, but advanced. Includes are useful as a way to split source code in more files, either because is easier to manage smaller files or to use one part in different projects. Code: ; Without using registers: macro switch a,b{ push [a] push [b] pop [a] pop [b] } Quote:
If you are calling this macro from a source that have access to dk_setupGUI macro definition it will work. But if the definition is accessible only through 'win32ax.inc' it won't work. i.e. this type of recursiveness does not work. Code: ;filename: test.inc macro dk_setupGUI{ format PE GUI 4.0 entry start include 'test.inc' };end macro dk_setupGUI |
|||
24 Aug 2004, 03:38 |
|
Tomasz Grysztar 24 Aug 2004, 09:32
Quote: So recursive macros are impossible. This is not really true. The "invoke" nesting macros from WIN32AX.INC file in FASMW package demonstrate some kind of the macro recursion in action. A bit complicated, but possible. |
|||
24 Aug 2004, 09:32 |
|
halyavin 28 Aug 2004, 14:31
And use recursion instead of cycles in compicated macros; it is often helps. You can't write program that sorts array at compilation time using 'repeat' macro.
|
|||
28 Aug 2004, 14:31 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.