flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > calling a macro many times |
Author |
|
Picnic 01 Oct 2007, 17:15
Hi all,
Is there a way on which calling a macro many times does not duplicates the code? |
|||
01 Oct 2007, 17:15 |
|
vid 01 Oct 2007, 17:25
another macro, rept, irp, irps, ...
|
|||
01 Oct 2007, 17:25 |
|
vid 01 Oct 2007, 22:26
thimis: why dont you just use procedure then?
|
|||
01 Oct 2007, 22:26 |
|
Picnic 02 Oct 2007, 16:20
ok but can i use 'proc' 'stdcall' in dos 16 bit programming and pass parameters in procedures? is there an example?
|
|||
02 Oct 2007, 16:20 |
|
vid 02 Oct 2007, 18:14
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...
|
|||
02 Oct 2007, 18:14 |
|
LocoDelAssembly 02 Oct 2007, 20:22
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 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... |
|||
02 Oct 2007, 20:22 |
|
edfed 02 Oct 2007, 23:40
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 |
|||
02 Oct 2007, 23:40 |
|
Picnic 03 Oct 2007, 17:00
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.. |
|||
03 Oct 2007, 17:00 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.