I was wondering if there is a way to define variables in 8051 apart from using EQU. I tried the define storage directive but then the compiler gives errors. I would be grateful if anyone could let me know.
The Define Storage I'm used to ( "DS", I've always called it Define Space, sounds like the same thing), it to simply reserve a section of uninitialized memory. So even if you were not getting compiler errors, I don't know if this would do what you wanted.
These things depend a lot on the compiler. Different compilers, even for the same processor, can do these these things differently. Best bet is to go through the section of the manual called something like "Assembler Directives".
It seems like you want a different effect than EQU (merely gives a numerical value to a label, but does not define the space to store it.) Assemblers I am used to use DB (define byte), DW (define word), etc. to initialize values in memory. These are sort of like a combination of EQU and DS, reserve memory and initialize it to a value. Your assembler may use other abbreviations for these same directives.
You may even find directives for re-defining a storage space, good for temporary storage to be shared by different routines.
Same thing I think. Well, I am using Keil. I have tried DB and DS both but they do not work. Initially I thought I was using them the wrongly but then I checked at a few places, and the instruction I used (label: DS 1) does seem to be right.
Do not want to use EQU simply because I wouldn't know which memory location to reserve for my variable. Do you think Keil does not understand the DS directive?
The only way to know what directives a particular assembler understands it to consult the manual.
You say it "doesn't work". How doesn't it work? What is the exact error message from the assembler? Or is it a linker error? Or does the program just not work as you expect?
I know that some assemblers don't want colons after labels. I think some want DS on a separate line (like the line after the label). Look for an example in the documents and follow it, then read the exact error message to find where it is wrong. You might find that the error is something different than what you're thinking.
Assembler is not like "C" in that there is no published standard for how a particular assembler should work. Even with "C", different vendors seem to know how to do things "better" than the standard, so even there you sometimes have to go to the manual. It's anybodies guess about what the assembler is wanting, except if you get an error message from the assembler/linker.
Its working now! I have no idea why though. I just looked at the manual, Keil has it the same way I was using it. There must have been some other problem. Oh, yes, I was redefining a variable. Imagine I've spent hours on this!
I really didn't know that assemblers have no standard directives. Will consult the manual more often in the future.