flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
JohnFound 11 Dec 2010, 07:07
Well, in order to create code on the place where macro is invoked and data in some other place, you should separate data definition and create inside your macro, new macro (or define symbolic constant) with data definition, that to be invoked in the place where you want to put data.
For example, download Fresh and see the file "include/macro/globals.inc". |
|||
![]() |
|
cod3b453 11 Dec 2010, 17:47
I not sure what you're trying to do exactly but here's one way.
Code: format binary as 'out.asm' macro MakeCodeAndData [d,c] { common db '.data',0x0D,0x0A db ' db 0x00',0x0D,0x0A forward db ' db '#`d,0x0D,0x0A common db '.code',0x0D,0x0A forward db ' mov al,'#`c,0x0D,0x0A } MakeCodeAndData 2,15,\ 12,11,\ 17,12 This will compile a new source file with added data, code that you can then also compile to executable. If you have a lot of other data or code, you can use the file 'some/file.name' in place of the macro db's to include a data and code source files instead of defining the source in the string. |
|||
![]() |
|
SPTH 13 Dec 2010, 00:15
Thank you JohnFound and cod3b453!
cod3b453 - I've tried your way first, it worked, but just if I can call the macro one single time. I dont know if I can do that in the further progress of the code, so I can not use it. However, it is a very nice solution, I may use that information for other projects Thank you! JohnFound: I have checked the source you suggested and read more about macros in macros etc. Very interesting topic. I nearly succeeded using a multi-macro solution (the problem was, that i wanted to use macro InSideMacro#COUNTER arg,val { ... }. I could define that, but could not call InsideMacro0, InsideMacro1, ... I dont know why. But when I read further about FASM macros, and using the idea with separation of creation of code + data, i succedded with a simple list solution: Code: include '..\FASM\INCLUDE\win32ax.inc' list equ macro MakeCodeAndData arg, val { mov al, arg match any, list \{ list equ list,val \} match , list \{ list equ val \} } .data db 0x0 .code start: MakeCodeAndData 2,15 MakeCodeAndData 12,11 MakeCodeAndData 17,12 DataHere: db list .end start The only thing i was not able to produce is the list in the data-section - even if i put the data-section below to the code section. But that is not important to my project, so everything is good :) Thanks again for the help! |
|||
![]() |
|
SPTH 14 Dec 2010, 01:26
I have another question that is related to that topic:
This works: Code: include 'E:\Programme\FASM\INCLUDE\win32ax.inc' macro M c,arg { cmp eax, arg je Label#c inc al Label#c: } .data db 0x0 .code start: M 1,23 M 2,23 M 3,23 M 4,23 ret .end start but that does not work: Code: include 'E:\Programme\FASM\INCLUDE\win32ax.inc' macro M c,arg { cmp eax, arg je Label#c inc al Label#c: COUNT=COUNT+1 } .data db 0x0 .code start: COUNT=1 M COUNT,23 M COUNT,23 M COUNT,23 M COUNT,23 ret .end start Why cant I use a preprocessor-variable in connection with Labels? |
|||
![]() |
|
revolution 14 Dec 2010, 01:30
COUNT is not a preprocessor-variable. It is an assembler variable.
But for macros just us the local directive: Code: macro M arg { local .lab cmp eax,arg je .lab inc al .lab: } |
|||
![]() |
|
SPTH 14 Dec 2010, 15:40
Hey revolution,
thanks for the answere. But imagine I want to call that label at another place of the source, like for multiple SEHs in my code: Code: include 'E:\Programme\FASM\INCLUDE\win32ax.inc' macro SEH_TRY c { push dword[fs:0x0] mov eax,dword[fs:0x0] pop dword[ExcReg_prev] ; Save old Exception Handler (whatever it is) push SEH_Handler#c push dword[fs:0x0] mov dword[fs:0x0], esp ; this works! } macro SEH_EXCEPTION c { jmp SEH_NoException#c SEH_Handler#c: mov eax, dword[ExcReg_prev] mov dword[fs:0x0], eax } macro SEH_END c { jmp SEH_Finish#c SEH_NoException#c: push dword[ExcReg_prev] pop dword[fs:0x0] add esp, 8 SEH_Finish#c: } .data ExcReg_prev dd 0x0 .code start: SEH_TRY 2 invoke MessageBox, 0x0, "try2", "try2", 0x0 ; mov dword[0x0], eax SEH_EXCEPTION 2 invoke MessageBox, 0x0, "EX2", "EX2", 0x0 SEH_END 2 invoke MessageBox, 0x0, "fin2", "fin2", 0x0 SEH_TRY 1 invoke MessageBox, 0x0, "try1", "try1", 0x0 mov dword[0x0], eax SEH_EXCEPTION 1 invoke MessageBox, 0x0, "EX1", "EX1", 0x0 SEH_END 1 invoke MessageBox, 0x0, "fin1", "fin1", 0x0 invoke ExitProcess, 0x0 .end start I need an external variable then, would be easier to have a counter. What is the difference of preprocessor-variable and assembler-variable? |
|||
![]() |
|
baldr 14 Dec 2010, 18:08
SPTH,
Symbolic constant (that's what you're calling “preprocessor-variable”) is preprocessor's feature (i.e. it works when macroinstructions are processed). There is rept 1 var:expr { … } trick that allows some numeric computations during this compilation phase. Preprocessor is single-pass, thus some restrictions are implied (e.g. no forward reference). In your case, local macro-body-specific directive is enough to generate unique labels for each macroinstruction's invocation (along with some symbolic constant to pass generated name between associated macroinstructions). You may look at structuring macroinstructions from MACRO\IF.INC for example of such communication. |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.