Borut Razem wrote:
> Alan Carvalho de Assis wrote:
>
>> Hi David
>>
>> 2007/11/6, David Lucena <[EMAIL PROTECTED]>:
>>
>>
>>> --- Alan Carvalho de Assis <[EMAIL PROTECTED]> escribió:
>>>
>>>
>>>
>>>> Hi,
>>>> I verify that SDCC can't compile macros if it have more than one
>>>> assembly line wrapped by _asm/_endasm.
>>>>
>>>> In example:
>>>>
>>>> #define SAVE_TASK_CTX(stack_low, stack_high) \
>>>>
>>>> { \
>>>>
>>>> /* Disable global interrupt. */ \
>>>>
>>>> _asm \
>>>>
>>>> bcf INTCON, 6, 0 \
>>>>
>>>> movff STATUS, PREINC1 \
>>>>
>>>> movff WREG, PREINC1 \
>>>>
>>>> _endasm \
>>>>
>>>> /* Store the necessary registers to the stack. */ \
>>>> ...
>>>> }
>>>>
>>>>
>>> Have you noticed that the _endasm avobe has not ';'. Can you verify that is
>>> that way in your code?
>>>
>>>
>>>
>> Before wrap each line I just placed the ';' but the generated code
>> (.asm) was wrong:
>>
>> bcf INTCON, 6, 0 movff STATUS, PREINC1 movff WREG, PREINC1
>> movff BSR, PREINC1 movff FSR2L, PREINC1 movff FSR2H, PREINC1 movff
>> FSR0L, PREINC1 movff FSR0H, PREINC1 movff TBLPTRU, PREINC1 movff
>> TBLPTRH, PREINC1 movff TBLPTRL, PREINC1 movff TABLAT, PREINC1 movff
>> PRODH, PREINC1 movff PRODL, PREINC1
>> movlw 0x20 +1 clrf FSR0L, 0 clrf FSR0H, 0
>>
>> As you can see the compile placed all instruction wrapped by
>> _asm/_endasm into a single line.
>>
>>
>>
> The C preprocessor coverts all the '\' delimited lines into a single
> line (this is the correct behavior) and pass it to the C compiler. The C
> compiler just pass everything between __asm and __endasm; directly to
> the assembler. So if the assembler doesn't know how to assemble multiple
> instructions in a single line, you have a problem. An it seems that
> gpasm is such an assembler...
>
> I think that your workaround to put each asm line in a sparate
> __asm/__endasm; block is correct.
>
Just an additional advice:
it is safer to put the complete multi line macro in a do/while(0) loop:
#define SAVE_TASK_CTX(stack_low, stack_high) \
do { \
/* Disable global interrupt. */ \
_asm \
bcf INTCON, 6, 0 \
_endasm; \
_asm \
movff STATUS, PREINC1 \
_endasm; \
_asm \
movff WREG, PREINC1 \
_endasm; \
/* Store the necessary registers to the stack. */ \
...
} while (0)
so that the following cases work correctly:
if (...)
SAVE_TASK_CTX(stack_low, stack_high);
if (...)
SAVE_TASK_CTX(stack_low, stack_high);
else
...
Borut
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user