flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > calling a macro many times

Author
Thread Post new topic Reply to topic
Picnic



Joined: 05 May 2007
Posts: 1288
Location: Paradise Falls
Picnic
Hi all,
Is there a way on which calling a macro many times does not duplicates the code?
Post 01 Oct 2007, 17:15
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
another macro, rept, irp, irps, ...
Post 01 Oct 2007, 17:25
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1288
Location: Paradise Falls
Picnic
hello vid thanks for the reply,
i was thinking for a macro acts somehow like a procedure.
a macro that expands the assembly code in a specific location and then call to this location if detected multiple calls.
Is this possible?
idea source..sharing some thoughts with a friend assembler

also something more,
is fasm supporting proc...endp ?
Post 01 Oct 2007, 18:18
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
thimis: why dont you just use procedure then?
Post 01 Oct 2007, 22:26
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1288
Location: Paradise Falls
Picnic
ok but can i use 'proc' 'stdcall' in dos 16 bit programming and pass parameters in procedures? is there an example?
Post 02 Oct 2007, 16:20
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
as far as i know there are no macros written for DOS procedures. but you don't need macro at all, you just need to understand how procedure work. Try to search forum and google for "stack frame", "stdcall", etc...
Post 02 Oct 2007, 18:14
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
I ported PROC32.inc to 16-bit and posted somewhere on the forum. It was to support only flat mode as far as I can recall and never fully tested.

Anyway, the idea behind a macro that does not duplicates its code is more or less this:

"PROCS.INC"
Code:
theXorParty.counter = 0
macro theXorParty setup
{
if ~setup eq
  theXorParty.proc:
  if theXorParty.counter > 1
    theXorParty.multipleUses = 1
  end if
end if

if (~defined theXorParty.multipleUses & setup eq) | (defined theXorParty.multipleUses & ~setup eq)

;;;;; BODY 
  xor     eax, eax
  xor     ebx, ebx
  xor     ecx, ecx
  xor     edx, edx
;;;;; BODY END
  if ~setup eq
    ret
  end if
else if setup eq
  call    theXorParty.proc
end if

  theXorParty.counter = theXorParty.counter + 1
}    


"MAIN.ASM"
Code:
include "PROCS.INC"
format PE GUI

  theXorParty
  ret

;;;;;;;;; Procedures placement (when needed)

theXorParty 1    


Resulting code:
Code:
00401000 >/$ 31C0           XOR EAX,EAX
00401002  |. 31DB           XOR EBX,EBX
00401004  |. 31C9           XOR ECX,ECX
00401006  |. 31D2           XOR EDX,EDX
00401008  \. C3             RETN    


And with this code
Code:
format PE GUI

  theXorParty
  mov eax, "loco"
  theXorParty
  theXorParty
  ret

;;;;;;;;; Procedures placement (when needed)

theXorParty 1    
You get:
Code:
00401000 >/$ E8 10000000    CALL test.00401015
00401005  |. B8 6C6F636F    MOV EAX,6F636F6C
0040100A  |. E8 06000000    CALL test.00401015
0040100F  |. E8 01000000    CALL test.00401015
00401014  \. C3             RETN
00401015  /$ 31C0           XOR EAX,EAX
00401017  |. 31DB           XOR EBX,EBX
00401019  |. 31C9           XOR ECX,ECX
0040101B  |. 31D2           XOR EDX,EDX
0040101D  \. C3             RETN    


Obviously this is not very handy because there are no macros here that handles the inlining and duplication prevention, you are doing it by yourself for every macrosed procedure. This code shows more or less how the hypothetical macroses would transparently construct your procedures so you only have to write the body, but in the meantime you have to do the transparent part yourself too...
Post 02 Oct 2007, 20:22
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
why do you want a macro
it's simplest to write a procedure and call it
if you don't know if you use the procedure you can erase it and fasm will return you a message of undefined symbol if you need it

it's nasty but it works very well and you don't have to write strange unlike asm code macro

speaking about conditional assembly, there is a full help about it in the fasm user manual
you just have to read it
Post 02 Oct 2007, 23:40
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1288
Location: Paradise Falls
Picnic
vid & edfed thanks both for your comments, suggestions.
Well, i'm reading a lot of stuff this period including fasm manual.
LocoDelAssembly thanks for this simple and interesting example code.
I think i locate the post for proc16 here
i'll use it and tell you more..
Post 03 Oct 2007, 17:00
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.