flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Growing list of params Goto page 1, 2 Next |
Author |
|
revolution 30 Sep 2010, 01:14
This the the equ problem. Use match to dereference it:
Code: macro meow [a] { a dd 0 } kitty equ cat1, cat2 match kat,kitty {meow kat} |
|||
30 Sep 2010, 01:14 |
|
cvtss2sd 30 Sep 2010, 01:39
Thank you for your response.
Code: macro meow [a] { a dd 0 } kitty equ cat1, cat2 macro usemeow [a] { common usemeowtemp1 equ 0 usemeowtemp2 equ 0 usemeowtemp3 equ 0 usemeowtemp4 equ 0 usemeowtemp5 equ 0 usemeowtemp6 equ 0 usemeowtemp7 equ 0 iters = 0 forward match kat, kitty \{ tempmeow7 equ tempmeow6 tempmeow6 equ tempmeow5 tempmeow5 equ tempmeow4 tempmeow4 equ tempmeow3 tempmeow3 equ tempmeow2 tempmeow2 equ tempmeow1 tempmeow1 equ kat \} iters = iters + 1 common if iters = 1 meow usemeowtemp1 end if if iters = 2 meow usemeowtemp1, usemeowtemp2 end if if iters = 3 meow usemeowtemp1, usemeowtemp2, usemeowtemp3 end if if iters = 4 meow usemeowtemp1, usemeowtemp2, usemeowtemp3, usemeowtemp4 end if if iters = 5 meow usemeowtemp1, usemeowtemp2, usemeowtemp3, usemeowtemp4, usemeowtemp5 end if if iters = 6 meow usemeowtemp1, usemeowtemp2, usemeowtemp3, usemeowtemp4, usemeowtemp5, usemeowtemp6 end if if iters = 7 meow usemeowtemp1, usemeowtemp2, usemeowtemp3, usemeowtemp4, usemeowtemp5, usemeowtemp6, usemeowtemp7 end if } usemeow kitty Now it says something else is wrong. |
|||
30 Sep 2010, 01:39 |
|
revolution 30 Sep 2010, 06:42
You have not used the "a" parameter anywhere in the usemeow macro.
Also you have mixed pre-processor and assembler stage statements. macro, match, forward, common are preprocessor stage statements. "if" is an assembly stage statement. You have not used "match" to dereference "kitty" in the last line. |
|||
30 Sep 2010, 06:42 |
|
cvtss2sd 30 Sep 2010, 07:35
I worked on this further taking your suggestions, then i notice an error in my logic. This is the final example of how to solve the problem. Thank you, it works!
Code: kitty equ cat1, cat2, cat3, NULLTERMINATOR macro meow [a]{ a dd 0 } macro usemeow param { match a1 =, b1, param \{ iters = 1 usemeowtemp1 equ a1 match a2 =, b2, b1 \\{ iters = 2 usemeowtemp2 equ a2 match a3 =, b3, b2 \\\{ iters = 3 usemeowtemp3 equ a3 \\\} \\} \} if iters = 1 meow usemeowtemp1 end if if iters = 2 meow usemeowtemp1, usemeowtemp2 end if if iters = 3 meow usemeowtemp1, usemeowtemp2, usemeowtemp3 end if } usemeow kitty dd cat3 Now, to generate a very large version of this code for my importing macro... |
|||
30 Sep 2010, 07:35 |
|
revolution 30 Sep 2010, 07:48
cvtss2sd: What do you actually want to do? The macro you have written looks just like a more complex version of the one used in the first post.
If you can explain what input you have and what output you want then there is probably an easier way to do it. |
|||
30 Sep 2010, 07:48 |
|
cvtss2sd 30 Sep 2010, 09:01
This is for an import macro of sorts. The structure of the file (ELF) sort of requires that the macro doing the actual importing is only used once. My hope was to be able to create a system that would look something like this:
Code: include "clib.inc" ;contains symbols include "SDL.inc" ;contains symbols importlibs ;there's the single use macro segment readable writable executeable entry $ ;some code using SDL and clib invoke exit, 0 |
|||
30 Sep 2010, 09:01 |
|
revolution 30 Sep 2010, 09:13
So what do you want importlibs to actually do? What is in clib.inc? What is in SDL.inc?
Are you using invoke in an ELF file (for UNIX or Linux)? That is kind of weird. |
|||
30 Sep 2010, 09:13 |
|
cvtss2sd 30 Sep 2010, 09:37
revolution wrote: So what do you want importlibs to actually do? What is in clib.inc? What is in SDL.inc? Extension on kohlrak's macroinstructions. Basically, clib.inc would include strucs, common constants, and an equ which would contain a comma separated list of all the functions of clib. SDL.inc would be the exact same thing, only SDL instead of clib. importlibs would take that list and pass it to the "includes" macro. But using the solution i made above in trying to extend them seems to be having fasm "run out of memory." Perhaps i'm still mixing too much... |
|||
30 Sep 2010, 09:37 |
|
revolution 30 Sep 2010, 09:56
I need an example.
Do you have something like this? Code: ;from clib.inc clib equ "libgtk-x11-2.0.so", gtk_init,\ "libc.so.6", printf ;from SDL.inc SDL equ "libgtk-x11-2.0.so", gtk_init2,\ "libc.so.6", printf2 Code: match A:B,clib:SDL{includes A,B} |
|||
30 Sep 2010, 09:56 |
|
LocoDelAssembly 30 Sep 2010, 15:12
cvtss2sd, remember that since then fasm was improved and now you don't need to create plain binaries to get an ELF executable referencing shared libraries. Take a look in the latest Linux package (examples/elfexe/dynamic/*).
|
|||
30 Sep 2010, 15:12 |
|
cvtss2sd 01 Oct 2010, 06:26
Somehow those examples slipped by me. Although the problem still remains with them: import can only be used once. A better example, though, would be something like this:
Code: ;clib.inc imports equ imports, "libc.so.6" functions equ functions, printf, gets, rand, exit Code: ;gtk.inc imports equ imports, "libgtk-x11-2.0.so" functions equ functions, gtk_main_quit, gdk_pixbuf_new_from_file, g_signal_connect_data, gtk_box_pack_start, gtk_container_add, gtk_init, gtk_main, gtk_menu_bar_new, gtk_menu_item_new_with_label, gtk_menu_item_set_submenu, gtk_menu_new, gtk_menu_shell_append, gtk_vbox_new, gtk_widget_show_all, gtk_window_new, gtk_window_set_default_size, gtk_window_set_icon, gtk_window_set_position, gtk_window_set_title Code: ;main.asm include "importing.inc" ;this would be where our magic macros to "importall" are defined include "clib.inc" include "gtk.inc" importall ;imports that defined by clib.inc and gtk.inc segment readable executable ;..code... call [exit] The idea would be to import functions and other data just like other assemblers and HLLs do it: simply with 1 include that only imports that which is used. That way one doesn't have to continually keep track of what functions one does and doesn't use throughout the program and simply type each and everyone that the assembler says is undefined at assemble time. It'd be much easier for the common Joe to simply grab a few include files which import the functions of the libraries they use, rather than trying to make huge lists for each and every program he makes (like the api/ includes for the windows version). |
|||
01 Oct 2010, 06:26 |
|
revolution 01 Oct 2010, 06:40
Since that is what you are trying to do then have a look at my Principles post. Especially Appendices A & B.
[edit] Which reminds me I recently made a newer version of the list building macros that use much less memory. I need to update that thread to reflect the change. Check back later, I will try to update within the next few days. |
|||
01 Oct 2010, 06:40 |
|
cvtss2sd 01 Oct 2010, 08:32
Appendix A would easily take at least one include off. Not sure what to do with appendix B, though. Maybe i'm just not understanding the code, but from my understanding, though, what you have provided is merely an example of the framework for each include file. Ultimately, though, I have no idea where this could lead into multiple includes into a single statement (perhaps that's what i don't understand about one of the macros provided by B).
I'll be sure to keep my eyes open. The URL's bookmarked. |
|||
01 Oct 2010, 08:32 |
|
revolution 01 Oct 2010, 09:38
cvtss2sd: How do you know which functions belong to which filename? You appear to be making two lists (imports & functions) but without any way of declaring which function belongs to which import.
|
|||
01 Oct 2010, 09:38 |
|
cvtss2sd 03 Oct 2010, 20:50
Unlike windows, linux (actually, this is part of the ELF standard, as you'll notice that binaries now don't have anything to link the functions to the libs) loads all the libraries, then searches for the functions within those libraries (you'll find you don't actually have to import libc.so.6 to import printf and other functions, because the lib is loaded automatically).
|
|||
03 Oct 2010, 20:50 |
|
revolution 03 Oct 2010, 21:14
cvtss2sd wrote: Unlike windows, linux (actually, this is part of the ELF standard, as you'll notice that binaries now don't have anything to link the functions to the libs) loads all the libraries, then searches for the functions within those libraries (you'll find you don't actually have to import libc.so.6 to import printf and other functions, because the lib is loaded automatically). |
|||
03 Oct 2010, 21:14 |
|
cvtss2sd 04 Oct 2010, 20:51
Not quite. They don't load all of the libs available (imagine the ram cost), just the ones you tell them. After that, they search the ones that are loaded for the functions (first using a hashing algorithm to first narrow it down). All libs and functions must still be referenced, however libs and functions may be separate (except in the strings table).
|
|||
04 Oct 2010, 20:51 |
|
revolution 05 Oct 2010, 01:00
Maybe you can make use the list building macro I posted here:
http://board.flatassembler.net/topic.php?t=12012 You will just need to make a small builder type macro to build the list and modify the "includes" macro to process the list. |
|||
05 Oct 2010, 01:00 |
|
cvtss2sd 06 Oct 2010, 15:20
I can't efficiently build them as you say (otherwise i'd replace printf with a0 or something like that which would be more confusing). But i think i have an idea how to do it, now. I should have less trouble if i use a loop.
|
|||
06 Oct 2010, 15:20 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.