Hi chris, yes and no actually. i assume that is in c, i am actually using assembly with an enhanced mid range pic. how is that converted into assembly?
movfw Var ;move into W
btfss Var,7 ;test if negative
goto notNegative ;no, so all done
comf Var,w ;complement and move to W
addlw 1 ;add 1 to complete negation
notNegative
The above loads W with the ABS value and leaves Var unchanged.
Edit, If you want the variable to be negated as well then do,
Code:
btfss Var,7 ;test if negative
goto notNegative ;no, so all done
comf Var,f ;complement and keep in file
incf Var,f ;add 1 to get complete negation
notNegative movfw Var ;mov into W