flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > How to define macro within macro ? |
Author |
|
Tomasz Grysztar 26 Feb 2012, 22:28
The simplest version would be without any macros really:
Code: wavpulse equ 0FAh,0FAh,0FAh,05h,05h,05h wavsilent equ 26 dup(80h) wavbit0 db 4 dup(wavpulse),wavsilent .size = $ - wavbit0 wavbit1 db 9 dup(wavpulse),wavsilent .size = $ - wavbit1 And with macros it could look like: Code: wavpulse equ 0FAh,0FAh,0FAh,05h,05h,05h wavsilent equ 26 dup(80h) struc wavbit %pulses { . db %pulses dup(wavpulse),wavsilent .size = $-. } wavbit0 wavbit 4 wavbit1 wavbit 9 |
|||
26 Feb 2012, 22:28 |
|
shutdownall 26 Feb 2012, 23:04
Thanks, that was fast and works great.
I didn't expect that I could pass a complex text sequence to EQU directive. |
|||
26 Feb 2012, 23:04 |
|
Tomasz Grysztar 27 Feb 2012, 10:53
EQU in fasm is just a textual substitution (as opposed to =, which is numerical), and is processed at preprocessor stage like macros (and it does almost the same thing as DEFINE directive).
It is important to know this distinction, otherwise you may fall in one of the traps: Code: a equ 2 + 2 b = 2 + 2 dd a*2 ; becomes 2 + 2*2, the result is 6 dd b*2 ; b=4, the result is 8 |
|||
27 Feb 2012, 10:53 |
|
shutdownall 27 Feb 2012, 22:30
Yes, thanks for pointing this out.
Another question regarding this definition: Code: wavbit0 db 4 dup(wavpulse),wavsilent .size = $ - wavbit0 wavbit0 seems to be a label which could be added with a property like size with the "." operator. Is this just a special case or could this be used to give any other property to a label ? I wonder if following would be possible to give size and maybe color (or any other attribute in context): Code: wavbit0 db 4 dup(wavpulse),wavsilent .size = $ - wavbit0 .color = 'green' |
|||
27 Feb 2012, 22:30 |
|
revolution 27 Feb 2012, 22:43
shutdownall: Did you try it? It does work as you will know when you assemble it. But be aware that 'green' is simply a number 0x6e65657267
|
|||
27 Feb 2012, 22:43 |
|
shutdownall 28 Feb 2012, 16:23
Okay. But can hold ascii values up to 8 chars(64 bit) - just in reversed order.
Also this works to give the duration of each wavbit in microseconds: Code: wavbit0 db 4 dup(wavpulse),wavsilent .size = $ - wavbit0 .duration = wavbit0.size*50 .color = 'magenta' |
|||
28 Feb 2012, 16:23 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.