flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > macro local labels |
Author |
|
vid 17 Jul 2007, 10:43
[moved this to Macroinstructions]
you mean something like this? Code: macro pushstr string { local x, y ;<-- here push y jmp x y db string x: } pushstr 'xyz' pushstr 'abcd' |
|||
17 Jul 2007, 10:43 |
|
pjd 17 Jul 2007, 11:10
That doesn't seem to work
this is the code Code: if_arguments: cmp edi, 0 ;are there any more arguments? je noarguments ;if not jump down .yesarguments: pop ecx ;pop the argument dec edi ;and say an argument is gone string_length eax mov edx, eax sys_write fd_console_out, ecx, edx put_char fd_console_out, 10 jmp .end .noarguments: .end: and the called macro Code: macro string_length string { mov eax, string lenloop: cmp byte [eax], 0 je .end inc eax jmp lenloop .end: sub eax, string } the .end in the code seems to think it follows from the lenloop in the macro instead of the if_arguments outside the macro p.s. thanks for moving the thread to the right place |
|||
17 Jul 2007, 11:10 |
|
vid 17 Jul 2007, 15:52
first of all, you shouldn't do this with macro, you should use procedure instead.
Do you understand what happens after preprocessor is done expanding macros? Your line "string_length eax" becomes: Code: mov eax, eax lenloop: cmp byte [eax], 0 je .end inc eax jmp lenloop .end: sub eax, eax ;<- uh-oh i suggest you to use procedure instead. PS: you shouldn't name your macro ".end" if you are using windows includes (win32ax.inc). I suppose you aren't, but just for sure... |
|||
17 Jul 2007, 15:52 |
|
pjd 17 Jul 2007, 18:45
the macro should have been given ecx not eax to work on. Thanks for spotting the bug.
I've been using NASM up till now and I am looking at whether FASM is better or not. In NASM I can define macros with labels like Code: %macro foo 0 ;code (can reference %%label) %%label: ;more code (can reference %%label) %end macro foo ;can't see %%label here because the label begins with %% it is macro local label and the %% gets exchanged for ..@ and a number. can I do that under FASM? (adding local lines in the macro doesn't work) I don't want to use procedure (with enter/leave) as it fiddles with the stack. |
|||
17 Jul 2007, 18:45 |
|
LocoDelAssembly 17 Jul 2007, 19:00
Code: macro foo { local ..label ..label: } foo ;Can't see ..label (unless you guess the UID in which case you can replace the Xs in ..local?XXXXXXXX with every digit of that number) here and it does not affect current scope since it starts with two dots. Quote: (adding local lines in the macro doesn't work) Why not? |
|||
17 Jul 2007, 19:00 |
|
vid 17 Jul 2007, 21:17
I splitted posts about FASM vs. NASM here
|
|||
17 Jul 2007, 21:17 |
|
pjd 18 Jul 2007, 09:04
LocoDelAssembly wrote:
silly me you need Code: local ..label Code: local label ;messes with .external_labels Thanks for showing me common sense |
|||
18 Jul 2007, 09:04 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.