On Fri, 30 Mar 2001 16:55:07 +0000, you wrote:
{Quote hidden}>I am not an expert on this, but I would tend to believe that since PICC
>keeps hands-off anything in an asm block, and since you don't use the
>variables source and result other than in the assembler block, that it
>just figures it doesn't need those two variables, so they don't exist for
>the assembler block to use. (W is used for passed values).
>
>As a test, perhaps add some do-nothing code that uses those variables
>within the function, or use static variables.
>
>Cheers,
>
>Bob
>
>> char reverse_bits(char source)// reverses bits 0 to 6 - source = 0ABCDEFG
>> {
>> char result;
>> #asm
>> swapf _source,w ;W= DEFG0ABC
>> btfsc _source,3 ; If D = 1,
>> xorlw 0x88 ;convert now sure W= 0EFGDABC
>>
>> btfsc _source,6 ;Test bit A
>> xorlw 0x05 ;Invert bits A and C
>> btfsc _source,4 ;Test bit C
>> xorlw 0x05 ;Invert bits A and C
>> ;now W = 0EFGDCBA
>> btfsc _source,2 ;Do the same with E and G
>> xorlw 0x50
>> btfsc _source,0
>> xorlw 0x50
>> movwf _result ;so now W = 0GFEDCBA (done)
>> #endasm
>> return(result);
>> }
>>
>> But, on building, the linker says that _source and _result are undefined variables. I thought that, to use a C variable in a piece of assembler code, you simply prepend an underscore to it. Anyone know what I'm doing wrong?
>>
I found that Hi-Tech had a nasty habit of optimising out vars that
were only used inside ASM blocks. I can't remember If I found a solution to this situation for return
vars. I think doing something like result=result;
outside the #asm can fix it, but can also generate unnecessary code.
The other problems is that with full optimisation on. it will
'helpfully' optimise out all your assembler code! I found it to be
much less hassle to put asm stuff in a seperate .as file. Under MPLAB this is relatively painless to do.
--
http://www.piclist.com hint: The PICList is archived three different
ways. See http://www.piclist.com/#archives for details.