This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: macro's and local variables
On Tue, Oct 16, 2012 at 11:37 AM, Mischa Baars <mjbaars1977@gmail.com> wrote:
> On 10/16/2012 08:20 PM, Ian Lance Taylor wrote:
>>
>> On Tue, Oct 16, 2012 at 11:12 AM, Mischa Baars <mjbaars1977@gmail.com>
>> wrote:
>>>>
>>>> Also one uses i and the other uses j, and that matters because
>>>> you are invoking them in a loop that also uses i.
>>>
>>> This is exactly what I'm pointing at. Apart from the register naming, I
>>> was
>>> expecting the same values to be assigned to the respective registers.
>>> This
>>> does not happen, because 'i' is not a local but a global value.
>>
>> Yes. That is how assembler macros work.
>
> So macro B is the only correct macro, as I understand.
I would say that it's the only one that may be correctly invoked by
macro C. In isolation both A and B are fine. Perhaps it is C that is
buggy.
>> Assembler macros are not a high level programming language. They are
>> macros: bodies of text that are expanded with argument values
>> substituted in textually. You may want to read about how \@ is
>> expanded in a macro body.
>
> I found the link:
> http://sourceware.org/binutils/docs-2.22/as/Macro.html#Macro
>
> However, I do not understand. Do you have an example?
.intel_syntax noprefix
.global function
.code64
.macro A arg1
.set i\@, 0
.rept \arg1
mov ax, i\@
.set i\@, i\@ + 1
.endr
.endm
.macro C
.set i\@, 0
.rept 4
A i\@
.set i\@, i\@ + 1
.endr
.endm
function:
C
ret