On Fri, 30 Mar 2001 16:55:07 +0000, you wrote: >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 =3D = 0ABCDEFG >> { >> char result; >> #asm >> swapf _source,w ;W=3D DEFG0ABC >> btfsc _source,3 ; If D =3D 1, >> xorlw 0x88 ;convert now sure W=3D 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 =3D 0EFGDCBA >> btfsc _source,2 ;Do the same with E and G >> xorlw 0x50 >> btfsc _source,0 >> xorlw 0x50 >> movwf _result ;so now W =3D 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.=20 I can't remember If I found a solution to this situation for return vars.=20 I think doing something like=20 result=3Dresult; outside the #asm can fix it, but can also generate unnecessary code.=20 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.=20 Under MPLAB this is relatively painless to do.=20 -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.