PDA

View Full Version : Get a 62.5% more program space easily



serandre
- 6th April 2006, 19:07
If you use too much strings (A-Z), you can easy get a 62.5% more space, since only 5/8 of the byte is used for the ASCII chars, this let us with a 3/8 wasted space of a byte that serves nothing.

So a string like this:
"HELLO WORLD LETS WASTE SOME BITS"

that takes 32 bytes (256 bits) could be coded as a 5 bit per ASCII character and ocupies only (160 bits), or 20 bytes !!!!!!

The downside is only that if you need to change the string, you will need to code it again, and once coded it's not possible to read it.

But considering some pics like 12f675 that only have a 1k of memory, having this type of code can save your project.

An example could be some type of REMOTE CONTROL decoder, that uses LOOOOTTTTTs of ASCII chars to show on a LCD the command descriptions, etc.... This takes a loot of memory.

To code the strings just subtract from each char (-65), so a "A" (ASCII 65) char will be coded as 0, B will be 1, etc...

Example:
HELLO --> ASCII 72, 69, 76, 76, 79 will be
HELLO --> CODED 7, 4, 4, 14
BINARY SEQUENCE --> 00111 00010 00010 01110
BYTE SEQUENCE --> $38, $84 $E0

See, the HELLO would take 5 bytes, after coded it took 2 1/2 bytes, and yeat there's a space in the last byte to more 1 char !!!

Hope this idea could be usefull to someone, I'm using it with my remote control project, if not using this type of code it would be impossible to me use a Pic12f675.

mister_e
- 6th April 2006, 19:37
interesting idea if you only need plain text in Upper Case. Good job! Now how do you save this to your codespace?

Did you already look here for a thread called Embedded String in your code space?
See the short story there http://www.pbpgroup.com/modules/wfsection/article.php?articleid=10

Easier does it?

serandre
- 7th April 2006, 03:34
interesting idea if you only need plain text in Upper Case. Good job! Now how do you save this to your codespace?

Did you already look here for a thread called Embedded String in your code space?
See the short story there http://www.pbpgroup.com/modules/wfsection/article.php?articleid=10

Easier does it?

In fact it's possible to use any character using a 5bits coding:

Since A-Z is only 26 letters, the 5 bits coding has a remaining 5 position to be used as controls like bellow:

I prefer to use the default as a lower case chars. (abcdef...)
So A-Z are coded as a=1, b=2, c=3, d=4...till z=26

As controls I use:
0 - End of string
27 - Space char
28 - Begin/End mark for a upper case string
29 - Begin/End mark for numbers 0-9
30 - Begin/End mark for symbols +-,.!$%^ (max 26 symbols each one is a char A-Z)
31 - Reserved, I have in nothing in mind in the moment :-)

So I code the string this way:

Source:
"/t/hese /word/ is in upper case this year is [bjjf]"

the ouput:
"This WORD is in upper case this year is 2006"

I am doing this ... errr... by hand :-) transforming the string directly to bits, it's a hell of work i know, I need just to create a program to translate the strings (Source above) to the bits and coded as i want.

Well, this idea I took from the HTML format, so even with as little as 5 bits I can get any char in a compact size :-)

mister_e
- 7th April 2006, 07:04
with the previous link, it will take the same code space (+/- few bytes) and you'll never have to translate your strings. Make things really much easy when you need to modify or add any strings.

Another idea is to save your string (or part of) in the internal EEPROM. Using your method or a variant of will permit to store 256 character in the internal EEPROM. I don't know how your string eat space but it could work too.

flotulopex
- 28th February 2007, 12:29
Hello Seandre,

Any example on how you retrieve the code please?

Sean_Goddard
- 8th March 2007, 19:32
Better still, why not code your words as TOKENS??

Store all the words you are likely to use in a table in the EEPROM in the PIC, then reference them using numbers;

Example;

PRESS, ANY, BUTTON, DOWN, THE

PRESS THE DOWN BUTTON becomes 1,5,4,3 you can delineate the words with a number say 27 as you will only ever use characters 1-26 anyhow, when the exctract routine sees a "27" it knows that is the end of the word.

Hope this helps.