Memory map - Constants
RickH
Posts: 40
Why do I not see constants in memory map?
I keep adding constants and nothing changes in memory map. I am asuming they are stord in the EPROM but like I said I see no changes as I add them. I have added every type %11111111, $DD, "ABC" and 128. None of them individualy or all at the same time change my memory map.
I keep adding constants and nothing changes in memory map. I am asuming they are stord in the EPROM but like I said I see no changes as I add them. I have added every type %11111111, $DD, "ABC" and 128. None of them individualy or all at the same time change my memory map.
Comments
-Phil
Post Edited (RickH) : 5/19/2008 3:09:34 AM GMT
If you declare a constant like %111 like "something CON %111", it doesn't allocate anything. The name "something" just becomes another way of writing "%111", a way that may have more meaning for you than just writing "%111".
Now, when you USE the CON, THAT takes up space. An example:
MyBaud CON 16468 ' CON 'entry', takes up no space in eeprom
SEROUT 16, MyBaud, [noparse][[/noparse]"Hi", CR] ' Okay, HERE some space is used to 'instantiate' the CON values. The 'Word' value 16468 is plugged in where "MyBaud" is.
That being the case, I'm pretty sure most "CON" instantiatiations take up a BYTE (if 0 to 255) or a WORD (if 256 or above) in the eeprom.
Post Edited (allanlane5) : 5/19/2008 2:19:18 PM GMT
You can use the memory map to look explore the effect using a simple program:
for example, if you try x=%11, then x=%111 and x=%1111, and look at the memory map, you will see the program grown by one bit at each step. Bring up the memory map (CTRL-M), and remember that the size of the program grows from high memory downward:
The program size is indicated by the position of the final 1 on the right, although a couple of zeros after that are significant and indicate end of statement and end of program.
If you change x VAR WORD to a smaller chunk, i.e., BYTE, NIB or BIT, the program will become longer. That is because the pointer to select the chunk becomes longer, one of 13 words, one of 26 bytes, one of 52 nibs, one of 208 bits.
PBASIC treats powers of two as an exceptional case. If you try x=%1 and then x=%1000000000000000, you will find that the space required is the same (for all powers of two) and it is as compact as it can get. I quite often take advantage of that in my programs. For example, if I need a timeout of about 1 second, I will use 1024 instead of 1000. Saves seven bits.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Post Edited (Tracy Allen) : 5/19/2008 4:49:32 PM GMT