Jump to content
Angosity

Problem With Rom Variable

Recommended Posts

I have written a program for 16F84 using char array and I want to move it to rom to save ram space.

If I compile using

const unsigned char patterns [26] =

{

2, 7, 5, 3, 1, 13, 1, 15, 3, 8, 2, 11, 0, 1, 0, 9, 2, 5, 7, 0, 6, 14, 4, 6, 4, 3 } ;

void main ( void )

{

unsigned char a;

a = patterns[1];

}

ram usage is 27 bytes Heap 41 ROM used 58 words

If I change it to

rom const unsigned char patterns [26] =

{

2, 7, 5, 3, 1, 13, 1, 15, 3, 8, 2, 11, 0, 1, 0, 9, 2, 5, 7, 0, 6, 14, 4, 6, 4, 3 } ;

I get Ram usage 31 bytes Heap 37 bytes and ROM used 53 words

 

Looking at the asm files it seems that Boostc is allocating the ram space for variable patterns in both cases.

If rom keyword is used then a lookup table is written to rom while if rom is not used an equivalent use is made of rom to write the values in the ram. This explains why the rom usage is similar in both cases.

However I do not understand why the Ram is allocated when the rom keyword is used

 

Extract from asm when rom is used

gbl_intcon EQU 0x0000000B ; bytes:1

gbl_patterns EQU 0x0000000C ; bytes:26

main_1_a EQU 0x00000026 ; bytes:1

 

when rom is not used

gbl_intcon EQU 0x0000000B ; bytes:1

gbl_patterns EQU 0x0000000C ; bytes:26

main_1_a EQU 0x00000026 ; bytes:1

 

How do I stop the ram allocation when keyword rom is used?

Share this post


Link to post
Share on other sites
I have written a program for 16F84 using char array and I want to move it to rom to save ram space.

If I compile using

const unsigned char patterns [26] =

{

2, 7, 5, 3, 1, 13, 1, 15, 3, 8, 2, 11, 0, 1, 0, 9, 2, 5, 7, 0, 6, 14, 4, 6, 4, 3 } ;

void main ( void )

{

unsigned char a;

a = patterns[1];

}

ram usage is 27 bytes Heap 41 ROM used 58 words

If I change it to

rom const unsigned char patterns [26] =

{

2, 7, 5, 3, 1, 13, 1, 15, 3, 8, 2, 11, 0, 1, 0, 9, 2, 5, 7, 0, 6, 14, 4, 6, 4, 3 } ;

I get Ram usage 31 bytes Heap 37 bytes and ROM used 53 words

 

Looking at the asm files it seems that Boostc is allocating the ram space for variable patterns in both cases.

If rom keyword is used then a lookup table is written to rom while if rom is not used an equivalent use is made of rom to write the values in the ram. This explains why the rom usage is similar in both cases.

However I do not understand why the Ram is allocated when the rom keyword is used

 

Extract from asm when rom is used

gbl_intcon EQU 0x0000000B ; bytes:1

gbl_patterns EQU 0x0000000C ; bytes:26

main_1_a EQU 0x00000026 ; bytes:1

 

when rom is not used

gbl_intcon EQU 0x0000000B ; bytes:1

gbl_patterns EQU 0x0000000C ; bytes:26

main_1_a EQU 0x00000026 ; bytes:1

 

How do I stop the ram allocation when keyword rom is used?

 

Don't use the [] syntax when using rom pointers (my example uses a PIC16F648A as the target):

 

 

rom const unsigned char * patterns =
{
2, 7, 5, 3, 1, 13, 1, 15, 3, 8, 2, 11, 0, 1, 0, 9, 2, 5, 7, 0, 6, 14, 4, 6, 4, 3 };

void main ( void )
{
unsigned char a;
a = patterns[1];
}

 

Memory Usage Report

===================

RAM available:256 bytes, used:6 bytes (2.4%), free:250 bytes (97.6%),

Heap size:250 bytes, Heap max single alloc:95 bytes

ROM available:4096 words, used:55 words (1.4%), free:4041 words (98.6%)

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...