Lookup command - observation

Jeremy Leach

Senior Member
Hi, just an interesting and a bit puzzling observation. I've been playing around a lot with long lookup commands. I've just noticed that for a lookup command containing strings :

String of 1 byte takes up 10 program space bytes.

String of 238 bytes (what my program uses) takes up 367 bytes. ie 129 extra bytes on top of the string itself !!! I'd be interested in an explanation of what appears to be a huge overhead in code storage space.

I'd become really keen on the Lookup command until I noticed this ;-)

I'm looking for ways to save program space now, so am now going to use the data storage space instead and write my own lookup subroutine, which I expect will execute slower.

Edited by - jeremy leach on 4/12/2005 3:03:57 PM
 

Jeremy Leach

Senior Member
Well actually lookup from Data storage (using Read command, predefined data is set using a very long EEPROM command) is MUCH faster than lookup using the Lookup command, which has speeded up my LCD routines nicely, and freed up loads of program space.
 

hippy

Technical Support
Staff member
The explanation for the LOOKUP overhead is that every number token includes a bit to indicate that it is a number token ( as opposed to a variable ), and more to indicate the size of the token. This gives every number in a LOOKUP a 3-bit overhead.

Smaller numbers, zero and one, use the least number of bits ( 4 in total ), two to 15 use 7 bits, 16 to 255 use 11 bits, and anything greater than 255 uses 19 bits.

On top of that there's the bits which indicate it is a LOOKUP command, which variables to use as the index and destination, plus there is a one bit flag after every number to indicate if there is more that follows and when the end of the list has been reached. It all adds up.

Using EEPROM with READ has the advantage that all data uses exactly 8-bits, and at run-time the Firmware doesn't have to step through the LOOKUP list to find the data needed and then step to the end of the LOOKUP to continue with the next statement, so READ is much quicker. There's also the advantage as stated that the EEPROM data is often held separately from program code, which also has its advantages.

The advantage that LOOKUP has over EEPROM is that variables can be used to return data, and data can have a value greater than 255. LOOKUP allows the effective creation of an array of bits ( or pins, or byte or word variables ) for reading ...

- LOOKUP bitIndex,(bit0,bit1,bit2,bit3, ... ),destVar
 

Jeremy Leach

Senior Member
Thanks Hippy, that's interesting.

I didn't realise the data in a lookup could be > 255. The advantage from my point of view in my project of using Lookup is that it uses Program storage. I've got no external memory and want to keep a portion of data storage for other things.
 
Top