Thorpydo said:
Hey, and thank you for the help!
"You do know that the variable directive makes a preprocessor variable at compile time, not a runtime variable?"
- I didn't know that, and still don't know exactly what that means. I don't know what a preprocessor variable or runtime variable are. I was using the variable directive just like I would a byte only because it was simlier to write and understand. Is that the wrong use for it?
Yes it is - it's an 'assembler directive', when you assemble the program it inserts the 'numeric value' of the variable into the program.
For an example, you write a program that can be used in two different versions - say it's a game, either a two player or four player game. Most of the source code will be identical, but there will be parts (obviously) where you will need either 2 or 4 inserting in the program. By using a variable directive you can assign the value 2 or 4 to a variable, which you insert at the required point.
Then to assembler either version of the game you simply alter the variable to 2 or 4 as you require, and when you assemble it makes the correct version.
A common use is assembling for different processors, you set a variable to the particular processor you're using, then the source checks the variable and assembles the correct code - something like this:
Code:
Processor = 16F84
If processor = 16F84 Then
use this bit
If Processor <> 16F84 Then
use this bit
But really the assembler variables are nothing to do with your program, just variables within the assembling process - generally you don't need them, and you are doomed to failure if you try to use them to write programs.
Try assembling a program, then disassembling it (you can use WinPicProg for this) - then compare it to what you started with. The latest beta version of WinPicProg even inserts variable names (which it obviously has to make up), so you can easily spot variables (registers) and constants (numbers)