flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > looping through arguments with forward

Author
Thread Post new topic Reply to topic
gens



Joined: 18 Feb 2013
Posts: 161
gens 05 Feb 2014, 21:34
i'm trying to make a good enough amd64 fastcall macro

it should go through the args and put them in reverse order
so it ends up like

mov rdx, something
mov rsi, something
mov rdi, something
call function

i want it to account for my stupidity
like if i use it with rdx as the first argument and have 3 arguments it should first mov rdi, rdx then mov rdx, something
so rdi dosen't get the wrong argument

i got that part planed using flags to skip what is done already (like idk "rdi_loaded=1")

the problem is that i need some kind of way to index arguments
i cant use forward blocks inside reverse blocks

hmm thinking about it now, i could put a forward inside if-else and recurse playing with flags

am i missing anything ?
can i stop and resume forward directives by any chance ?
anybody have a better idea ?

anyway this is a shell i'm using for testing

Code:
macro fcall routine, [ops] {
num_args = 0
num_floats = 0

forward
if ops eqtype 1.0f
num_floats = num_floats+1
else
num_args = num_args+1
end if

forward

if ops eqtype 1.0f
display "slot is float", 0x0a

else if ops eqtype rax
display "slot used", 0x0a
mov rax, ops
end if

common
display "routine", 0x0a
;call [routine]

display "0"+num_args, " reg or ptr op's used", 0x0a
display "0"+num_floats, " floats", 0x0a
}    


original macro is just a bunch of if-else without floats (has lea reg+imm support thou)

bdw were letters always this small when posting or is it just me
Post 05 Feb 2014, 21:34
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20563
Location: In your JS exploiting you and your system
revolution 05 Feb 2014, 21:45
Look at the included macros for fastcall that come with the fasm download. Tomasz has already solved this.
Post 05 Feb 2014, 21:45
View user's profile Send private message Visit poster's website Reply with quote
gens



Joined: 18 Feb 2013
Posts: 161
gens 05 Feb 2014, 22:08
sounds good
i cant find it in the linux version, win only ?
almost the same thing really so its np

edit: found it Smile
Post 05 Feb 2014, 22:08
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.