flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Modyfing array variable in compilation time |
Author |
|
edfed 25 Apr 2010, 20:29
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 |
|||
25 Apr 2010, 20:29 |
|
Tyler 25 Apr 2010, 21:08
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) } |
|||
25 Apr 2010, 21:08 |
|
LocoDelAssembly 25 Apr 2010, 21:34
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 |
|||
25 Apr 2010, 21:34 |
|
Tyler 25 Apr 2010, 21:50
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) } |
|||
25 Apr 2010, 21:50 |
|
LocoDelAssembly 25 Apr 2010, 21:56
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.
|
|||
25 Apr 2010, 21:56 |
|
baldr 25 Apr 2010, 22:42
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 ... pListFunctions dd labels_list |
|||
25 Apr 2010, 22:42 |
|
alorent 26 Apr 2010, 10:42
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! |
|||
26 Apr 2010, 10:42 |
|
baldr 26 Apr 2010, 14:49
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). |
|||
26 Apr 2010, 14:49 |
|
alorent 26 Apr 2010, 17:27
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! |
|||
26 Apr 2010, 17:27 |
|
baldr 27 Apr 2010, 05:37
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 |
|||
27 Apr 2010, 05:37 |
|
alorent 27 Apr 2010, 13:11
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!! |
|||
27 Apr 2010, 13:11 |
|
Tyler 28 Apr 2010, 03:02
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. |
|||
28 Apr 2010, 03:02 |
|
baldr 28 Apr 2010, 07:39
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 |
|||
28 Apr 2010, 07:39 |
|
alorent 29 Apr 2010, 07:11
Thanks baldr!!! That's another approach!
|
|||
29 Apr 2010, 07:11 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.