flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
edfed
i think it is.
macro support local variable, but supoprt global variables too. then, define a global pointer(equate?) to your array use the global pointer as an offset in the array update the pointer. in practice i don't know how to do. maybe it would be easier to create a function ot do this, and not a macro. and use a macro to call this fucntion macro add_func func{ push func call addfunc } call |
|||
![]() |
|
Tyler
If only I could find a way to store the address, I attempted to store the pointer with the last line but I get a weird error, "Error: code cannot be generated."
Code: if ~functions_added = 0 pListFunctions rd functions_added end if macro add_func addr { if ~functions_added = 0 functions_added = functions_added + 1 else functions_added = 1 end if store dword addr at (pListFunctions + (functions_added - 1) * 4) } |
|||
![]() |
|
LocoDelAssembly
Tyler, take a look at this:
Code: pListFunctions rd functions_added_final functions_added = 0 macro add_func addr { functions_added = functions_added + 1 store dword addr at (pListFunctions + (functions_added - 1) * 4) } alpha:ret beta:ret gamma:rep ret epsilon:ret add_func alpha add_func gamma add_func epsilon functions_added_final = functions_added |
|||
![]() |
|
Tyler
Loco: Nice, I was trying to keep everything self contained so that the variables were only processed if the macro was used, which complicated mine a little complicated. I still don't see where I screwed up.
I think this works, not so sure how to test it though. It assemblers w/o an error. Code: if defined functions_added pListFunctions rd functions_added end if macro add_func addr { if ~(defined functions_added) functions_added = functions_added + 1 else functions_added = 1 end if store dword addr at (pListFunctions + (functions_added - 1) * 4) } |
|||
![]() |
|
LocoDelAssembly
invoke add_func twice or more and you'll get an out of scope error. I'm not sure what was causing the "code cannot be generated" error in your earlier version, I was expecting something like the error you get now with multiple invocations of add_func.
|
|||
![]() |
|
baldr
alorent,
Would comma-separated list of labels suffice? You may use something like Code: macro append name, [value] { common match old_value, name \{ restore name name equ old_value, value \} match , name \{ ; list is empty, no separator necessary restore name name equ value \} } Code: labels_list equ ... append labels_list, Function1, Function2; and so on; 10 dup FunctionX is also valid |
|||
![]() |
|
alorent
Hello guys,
Thanks a lot for your help. Tyler, Loco: 1st of all, THANKS! I have tried your solutions, but when I write: add_func MyProc I get a compiler error "value out of range" Not sure if I have to call it in a different way. baldr: Thanks for giving another solution. Unfortunatelly, I cannot use that approach. The functions must be added independently (from different modules) and not setting up the whole list at once. Thanks! |
|||
![]() |
|
baldr
alorent,
That macro doesn't build list at once, it appends its arguments to list and can be invoked multiple times. Like any other preprocessor solution, the resulting list can be used only after the last append macro invocation. LocoDelAssembly's solution works OK for me. Note that exact order is important: functions_added = 0 should be before first add_func invocation, functions_added_final = functions_added should be after last (included files can mess with that). |
|||
![]() |
|
alorent
Hello baldr,
Thanks for the information. Sorry, I thought that your solution created the list at once. I have tried to use your solution but I think that I'm not doing it in the correct way: Code: include 'win32ax.inc' ; you can simply switch between win32ax, win32wx, win64ax and win64wx here include 'macro\if.inc' include 'macro\masm.inc' macro append name, [value] { common match old_value, name \{ restore name name equ old_value, value \} match , name \{ ; list is empty, no separator necessary restore name name equ value \} } .data labels_list: dd 10 dup (0) pListFunctions dd labels_list .code start: append labels_list, MyProc append labels_list, MyProc2 int 3 mov eax, pListFunctions MyProc proc ret MyProc endp MyProc2 proc ret MyProc2 endp .end start The resulting list is empty. Any ideas? Thanks! |
|||
![]() |
|
baldr
alorent,
You got it all the way wrong. ![]() Code: include 'win32ax.inc' ; you can simply switch between win32ax, win32wx, win64ax and win64wx here include 'macro\if.inc' include 'macro\masm.inc' macro append name, [value] { common match old_value, name \{ restore name name equ old_value, value \} match , name \{ ; list is empty, no separator necessary restore name name equ value \} } labels_list equ append labels_list, MyProc append labels_list, MyProc2 .data pListFunctions dd labels_list .code start: int 3 mov eax, pListFunctions MyProc proc ret MyProc endp MyProc2 proc ret MyProc2 endp .end start |
|||
![]() |
|
alorent
Thanks baldr!
Will that approach work on multiple asm files (linked as OBJ files) on a single list? That is, each module call its own "append" macros? Finally, one module (asm) will be the one that reads the whole list and process it. Thanks!! |
|||
![]() |
|
Tyler
No, you asked for something that affected code at compile time. Macros are processed before even the object code would be made.
You could do it at runtime, but I don't know of how to do such a thing with a linker because I don't use one. If you were to "link" the files by preprocessor-including them, it would work fine. |
|||
![]() |
|
baldr
alorent,
"Modyfing array variable in compilation time", heh? Well, even at link stage it is possible: linker merges similar (up to "$something" name suffix) sections. Code: ; This is the main source format MS COFF section ".text" executable public start start: mov eax, pListFunctions mov ecx, pListFunctionsEnd ret section ".data$a" readable pListFunctions: section ".data$c" readable pListFunctionsEnd: Code: ; This is the first function format MS COFF section ".text" executable Function1: mov eax, 1 ret section ".data$b" readable dd Function1 Code: ; This is the second function format MS COFF section ".text" executable Function2: mov eax, 2 ret section ".data$b" readable dd Function2 |
|||
![]() |
|
alorent
Thanks baldr!!!
![]() ![]() |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.