Do programs live in RAM or ROM? |
The memory specification file used during the linking stage breaks memory up into
The obvious question to ask is How come I can change which program I run when programs are unchangeable since they sit in ROM memory?
The SDS toolkit is designed for the embedded processor market. Embedded systems are "standalone", they must work on powerup. This means that your program code must be present in memory when the machine is switched on. The program code therefore must reside in ROM (typically an EPROM). Any data values stored in RAM will be zero on power up.
This RAM is zero on power-up would mean that it would not be possible to just have the following code example in Laboratory 1.
section data xxx DC.W 0x1234 ; Initialize some variables yyy DC.W 0xABCD
since the values "would not be there" in the data section when you downloaded your executable file into the SDS simulator. This little "subtle feature" took me many hours to work out what was happening the first time I tried the SDS simulator.
It would be possible for the start-up program to bring "its data" (from a diskette or hard-drive and load that into RAM. To you, the startup program's data is "your program".
The startup program could then do a JSR (jump to subroutine) into the middle of "its data" causing the processor to start executing the "data" as if it was a series of instructions. This has the effect of transferring execution from the start-up program to your program.
We have just said that we can't have constants in RAM, since the values are not there on power up of the embedded processor. Then how can we handle the following code segment
xxx DC.W 0x1234 ; Initialize variable xxx = 0x1234 mycode ; Start of "mycode" program ADD.W #1,(xxx) ; xxx = xxx + 1;
using the SDS simulator.
The answer is something like the following
section data xxx DC.W 0x1234 ; Initialize variable xxx = 0x1234 section code mycode ; Start of "mycode" program ADD.W #1, (xxx) ; xxx = xxx + 1; .........
section code startupcode ; Start of "startupcode" program Some code designed to take values from section "datasection_inROM" and move them to section "data" in RAM
JSR mycode
The SDS assembler will automatically take values associated with initialized variables and store them in datasection_inROM. It is then the responsibility of the programmer during the startup program to move values from this ROM memory section and place those values into RAM section data.
This transfer of data from one section to another seemed a little much for Laboratory 1. I therefore placed the constants A and B directly into section const. This section automatically gets loaded into "ROM" by the SDS simulator and the necessary values are available.
After you have completed Laboratory 1 in the manner suggested, you might like to make use of this data section. You would code your source file to place A and B in section data. and then move the values from section datasection_inROM to their proper locations. This would require modification of the startup.i file that was discussed during the simulation stage of Laboratory 1. The variable DATA is defined by the SDS linker as the start of the datasection_inROM values if you use the suggested memory specification file. This variable can be manipulated in the same way as the variable STKTOP is handled in startup.i.
Since the SDS simulator is intended as a "debugging" tool, it will actually allows modification of variables placed in ROM. This means that during the laboratories your code will work if you put a "variable" into the const section. You don't have to do the data shuffle trick.
This practice of "variables in ROM" would be unsatisfactory if you had to develop real life programs. In that situation you would have to move the data from datasection_inROM to data, and also to change the memory specification model to ensure that any attempts to modify ROM would get caught and the program corrected. The demo kit will not support this approach.
![]() |
Last modified: July 12, 1996 09:33 PM by M. Smith.
Copyright -- M. R. Smith