Overwritable SECTION in RAM

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Overwritable SECTION in RAM

3,173 次查看
Santa
Contributor I
I am traying to get a space of RAM to contain all my temp varaibles. This SECTION can be something like 16 bytes long, but the idea is for it to hold more than 16 varaibles. This means that some variables will share the same RAM location, and thy can because they are temporal!!!

I read on the CW help that using the PAGED directive in the .prm file can do the trick.

SEGMENTS /* Here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */
EEPROM = READ_ONLY 0xEE00 TO 0xEE40;
ROM = READ_ONLY 0xEE41 TO 0xFDFF;
FLASH_RAM = READ_WRITE 0x008C TO 0x0093;
Z_RAM = READ_WRITE 0x0094 TO 0x00DF;
TEMP_RAM1 = PAGED 0x00E0 TO 0x00EF;
TEMP_RAM2 = PAGED 0x00E0 TO 0x00EF;
ROM1 = READ_ONLY 0xFFB0 TO 0xFFBD;
ROM2 = READ_ONLY 0xFFC2 TO 0xFFCF;
END
PLACEMENT /* Here all predefined and user segments are placed into the SEGMENTS defined above. */
DEFAULT_ROM, ROM_VAR, STRINGS INTO ROM; /* ROM1,ROM2 In case you want to use ROM1,ROM2 as well, be sure the option -OnB=b is passed to the compiler. */
MyCode INTO ROM;
MyEeprom INTO EEPROM;
DEFAULT_RAM,
_DATA_ZEROPAGE, MY_ZEROPAGE INTO Z_RAM;
/* Secciones de los módulos */
EE_RAM INTO FLASH_RAM;
DTMF_RAM INTO Z_RAM;
SPI_RAM INTO Z_RAM;
MY_TEMP1 INTO TEMP_RAM1;
MY_TEMP2 INTO TEMP_RAM2;
END

(do a search for "OVERLAYS" in the CW help).

I used it but when MY_TEMP1 + MY_TEMP2 size exceeds 16 bytes the linker gyves me a "can't fit the section size" error.

Can anyone point me any other methods to get this working?

Thx

Horacio
标签 (1)
0 项奖励
回复
4 回复数

587 次查看
bigmac
Specialist III

Hello Horacio,

This may not be applicable to your case, but I would normally use the stack for any temporary variables (when programming in assembly code).  The stack pointer can then be adjusted when the variables are no longer required (when the sub-routine exits).

If you are programmin in C, this will occur automatically for local variables within a function.

Regards,
Mac

 

0 项奖励
回复

587 次查看
Santa
Contributor I
Hi Mac,

I know the Stack can be used for this purpose. But I trust more the C to asm translator build into Cw than my self. My use of stack knowledge is limited and I really don't use it much... I am thinking in starting to fo some tests and get the fill of it.

Thanks

Santa
0 项奖励
回复

587 次查看
Santa
Contributor I
Well i figured out the problem. In the .asm file I was using the same SECTION:

MY_TEMP1: SECTION SHORT
prot_cnt DS.B 1
...

MY_TEMP1: SECTION SHORT
time_temp1 DS.B 1
...


Once I changed the second SECTION to MY_TEMP2 it all resolved!
0 项奖励
回复

587 次查看
bigmac
Specialist III

Hello,

An alternative approach that could also be adapted for absolute assembly - simply use equates to define a new label for the different uses of each temporary variable, as required.

So the temporary variable block would be allocated only once.
MY_TEMP: SECTION SHORT
TEMP:    DS.B    16
         XDEF    TEMP

Then to use the variables in different modules of the program -
Case 1:
          XREF  TEMP
prot_cnt  EQU   TEMP+2
etc.

Case 2:
          XREF  TEMP
time_temp EQU   TEMP+2
etc.

Regards,
Mac

 

0 项奖励
回复