DATA Statements with Variables
hmlittle59
Posts: 404
Hello Everyone
I have a Data Statement such as...Data "Cost is $", Dollar, ".00", were (Dollar var byte) is defined. The Editor will not except it. It returns the error saying that it needs to be a constant. I changed...Dollar...to a constant and it was excepted...How can I get around this?
1) I need to place a variable statement within a DATA statement.
2) Text in front and Text after the variable
Any help...Thanks
hmlittle59
I have a Data Statement such as...Data "Cost is $", Dollar, ".00", were (Dollar var byte) is defined. The Editor will not except it. It returns the error saying that it needs to be a constant. I changed...Dollar...to a constant and it was excepted...How can I get around this?
1) I need to place a variable statement within a DATA statement.
2) Text in front and Text after the variable
Any help...Thanks
hmlittle59
Comments
You're right with #2. You can have the text before the variable part and the
text after the variable part and furnish the variable part separately.
I would probably take a look at the WRITE command in the BASIC Stamp Editor's Help file in order to store a variable's value in the BASIC Stamp's EEPROM.
My question is, what are you trying to do by storing text that needs to be in front of and after a variable?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"I learn when I succeed, but I learn more when I fail."
Alan Balich
SX/C Wiki - sxcwiki.alanbalich.com
DATA "Cost is $", $00, ".00", $00
Then your display routine can read characters from the data statement until the 0 byte is reached at which time it will display the value then continue reading the data statement from the last index until it reaches the next 0 byte, terminating.
I hope this helps. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
-Phil
I don't agree that including everything in the output arguments is necessarily less memory intensive. Each character stored as an output argument occupies 14 bits, whereas in a data statement the same character occupies only 8 bits. The break even point comes at only about a 15 byte string...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
For output of strings to the EMIC speech syth, I've used tags embedded in the fixed eeprom data. For example hex $95 embedded in the speech string would stop the direct output of the characters and instead branch to a routine that points to wordVariable(1) and outputs that to the EMIC using format number 5. In this situation, bit7=1 will not otherwise occur in the speech string, so that is what flags a control byte. There are thus 8 possible variables and 16 possible formats that can be embedded in the speech string to be played back, using the fixed data plus the current values of the variables at run time. It of course takes a playback subroutine to fetch the eeprom strings.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
You're right about the space required by embedded output lists. Wow! It's a bit of a shock, really, since other PBASIC tokens are stored so efficiently. (So much for logical assumptions!) There must be a command token associated with each character.
Anyway, I think I'd assign a higher number to the break-even point, if you want to compare apples with apples. Here are two programs that do the same thing in two different ways. First, the way I suggested (84 bytes):
Second, a more generic version of your program (112 bytes, including 40 bytes of DATA):
By my calculations, this puts the break-even closer to a string of 77 characters, which still isn't all that much.
I do like your idea of embedding tags in the string to signify variables. I only wish PBASIC were a little more expressive when it comes to aliasing and pointers, so a program like this could be made more readable. But that's for another thread. (Oh, right. 'Been there, already. )
-Phil
You are right about there being a command token associated with each byte, a "push literal" onto the expression stack. Other tokens are associated with various modifiers. The SEROUT command once set up reinvokes the interpreter to peel tokens and data off onto the expression stack an element at a time, and the the SEROUT then sends the characters it finds on the expression stack.
Fourteen bits per literal character is an average. It varies from 9 to 16 bits depending on the ascii value, and low ascii codes take less. The way the literal push token works, it can be more efficient for smaller values. Binary-valued codes like 32=space are a special case and all take 9 bits. The same mechanism is used any time there is an argument list of indeterminate length.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
I'm a bit confused by your description of how SEROUT uses the stack. Given the hardware involved (a small PIC for the BS2), there's not enough RAM to stack a string of any ponderable length to be peeled off for output later. Does the compiler chunk the output string into shorter segments? It must also have to stack things in reverse order so they come off in the correct order.
-Phil
All this is covered in fascinating detail in Brian Forbes' book.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Ah so. I've ordered the book on your recommendation. Thanks for the pointer! Now, somebody needs to write one for the BS2p series!
-Phil
All my other request combined never generate this kind of help. Thanks a bunch. I'm using the code like Phil's,
(SEROUT, iopin, baud, [noparse][[/noparse]"COST is $", DEC cost, ".00"]) showed. I needed the shorts code possible for my Main Menu. I've rewritten this code so much to get the size down I hardly recognize it. I have 9 byte free and all seems to be working GREAT. Thanks Again.
I'm using " PCB Artist " to layout my board and I don't have a clue what i'm doing. I've put most of the components on the screen and now have to connect them. I have two Proto Boards from Parallax and with help from Mike I gotten started there but it's been slow. With the software part done, maybe i can focus more on the next two phases. Getting it from paper to CAD has been even more of a challenge.
1) Has anyone used this Software before?
2) Are there any Public Domain files for the BS2 Micro's that I can just import in?
3) Any advise for some who just doesn't have a cluse
Thanks for any help
hmlittle59
When I was working in the original BS2, I was constantly up against the out of memory condition or vanishing free space, and had to go back to pruning and shaving here and there. The text prompts went into DATA statements and became super-abbreviated. Time delays where possible became say 1024 instead of 1000, just to save a few bits. Condition statements cut to the bone. Math statements condensed to the point of incomprehensibility. Now the BS2pe is a luxury--all that space! But of course nature abhors a vacuum.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
No, I haven't read McMannis, nor have I ever used the BS1. It's probably because the BS2 came along before I'd ever paid the BASIC Stamp line much attention. But the BS2 and BS2p series have become classics in their own right and — in my mind at least — retain durable standing against even the Propeller's siren song of power and capacity. Perhaps that's just my inherent minimalism talking. In any event, I truly believe the Stamps have ample staying power to justify further enhancements to their dev tools, thereby unlocking even greater ease of use. Given Forbes' book and the twin luxuries of time and treasure, I suppose one could dive in and do that job himself. I'm one for three — or will be once the book arrives!
-Phil