flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Growing list of params

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
cvtss2sd



Joined: 30 Sep 2010
Posts: 48
cvtss2sd
Code:
macro meow [a] {
  a dd 0 }

kitty equ cat1, cat2

meow kitty    


I seem to have a dilemma. I need to make a list X that can have stuff added to it that can ultimately be passed to a macro that can only be used once per program (I'm also considering a load solution, but this would be much cleaner than that). Any ideas?
Post 30 Sep 2010, 01:11
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17665
Location: In your JS exploiting you and your system
revolution
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}    
Post 30 Sep 2010, 01:14
View user's profile Send private message Visit poster's website Reply with quote
cvtss2sd



Joined: 30 Sep 2010
Posts: 48
cvtss2sd
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.
Post 30 Sep 2010, 01:39
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17665
Location: In your JS exploiting you and your system
revolution
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.
Post 30 Sep 2010, 06:42
View user's profile Send private message Visit poster's website Reply with quote
cvtss2sd



Joined: 30 Sep 2010
Posts: 48
cvtss2sd
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...
Post 30 Sep 2010, 07:35
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17665
Location: In your JS exploiting you and your system
revolution
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.
Post 30 Sep 2010, 07:48
View user's profile Send private message Visit poster's website Reply with quote
cvtss2sd



Joined: 30 Sep 2010
Posts: 48
cvtss2sd
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    
Post 30 Sep 2010, 09:01
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17665
Location: In your JS exploiting you and your system
revolution
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.
Post 30 Sep 2010, 09:13
View user's profile Send private message Visit poster's website Reply with quote
cvtss2sd



Joined: 30 Sep 2010
Posts: 48
cvtss2sd
revolution wrote:
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.


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...
Post 30 Sep 2010, 09:37
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17665
Location: In your JS exploiting you and your system
revolution
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    
If so, then just use
Code:
match A:B,clib:SDL{includes A,B}    
Post 30 Sep 2010, 09:56
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
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/*).
Post 30 Sep 2010, 15:12
View user's profile Send private message Reply with quote
cvtss2sd



Joined: 30 Sep 2010
Posts: 48
cvtss2sd
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).
Post 01 Oct 2010, 06:26
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17665
Location: In your JS exploiting you and your system
revolution
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.
Post 01 Oct 2010, 06:40
View user's profile Send private message Visit poster's website Reply with quote
cvtss2sd



Joined: 30 Sep 2010
Posts: 48
cvtss2sd
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.
Post 01 Oct 2010, 08:32
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17665
Location: In your JS exploiting you and your system
revolution
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.
Post 01 Oct 2010, 09:38
View user's profile Send private message Visit poster's website Reply with quote
cvtss2sd



Joined: 30 Sep 2010
Posts: 48
cvtss2sd
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).
Post 03 Oct 2010, 20:50
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17665
Location: In your JS exploiting you and your system
revolution
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).
So does that mean you don't need the "imports" equate list?
Post 03 Oct 2010, 21:14
View user's profile Send private message Visit poster's website Reply with quote
cvtss2sd



Joined: 30 Sep 2010
Posts: 48
cvtss2sd
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).
Post 04 Oct 2010, 20:51
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17665
Location: In your JS exploiting you and your system
revolution
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.
Post 05 Oct 2010, 01:00
View user's profile Send private message Visit poster's website Reply with quote
cvtss2sd



Joined: 30 Sep 2010
Posts: 48
cvtss2sd
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.
Post 06 Oct 2010, 15:20
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.