-----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On Thu, 29 Mar 2012 16:51:20 -0700 Rob wrote: > In my relocatable sub .asm file I have: > GLOBAL vFlag_var > vFlag_var res 1 ;register to hold flag bits >=20 > #define flag_X 2 ;define a label to a bit number for use > as a flag > GLOBAL flag_X ;this seems to generate a 121 error:=20 > "illegal label (2)" >=20 > Then in my main code file, I intended to access the flag with: > EXTERN vFlag_var > EXTERN flag_X > btfss vFlag_var, flag_X >=20 > So why does this not work ? Why does this cause an illegal label > error? You can only use GLOBAL and EXTERN on things which are generally called "symbols" or "labels". These are names understood by the assembler and linker and which eventually resolve to a memory address. Things allocated with "res" fall into this category, as do labelled instructions in code used as e.g. jump or call targets. Things defined with #define are not labels: they are pure textual substitutions, and they happen before assembly proper. "#define flag_X 2" performs a literal text substitution over the rest of the input file, thus your second command is in fact read as "GLOBAL 2", which makes no sense. You can't really use labels to refer to single bits anyway because bits don't have addresses; only bytes do. Your best solution is probably to create a header file ("something.inc") containing the #define flag_X 2 line, and #include it in the files that need to access the flag. Unfortunately (assuming MPasm works the same as GPasm), it looks like you can't also put the EXTERN there, because the file defining vFlag_var (with "res") would then see both EXTERN and GLOBAL for that symbol and blow up, assuming that file needs to #include "something.inc". You could put the EXTERN in all the .asm files that need it; alternatively, there may be a nice preprocessor trick or similar that someone on the list who's used assembly more recently than I have can suggest. Chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (GNU/Linux) iEYEAREDAAYFAk91IlUACgkQXUF6hOTGP7dkUACfeAyTr2MiAC6q5M4hRv9A2/H8 1S8An1c4GWpFk/fMMEf3esOhx1NyGBV9 =3D4iY+ -----END PGP SIGNATURE----- --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .